#ifndef CONTENT_SHELL_SHELL_H_
#define CONTENT_SHELL_SHELL_H_
#include <vector>
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_piece.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ipc/ipc_channel.h"
#include "ui/gfx/native_widget_types.h"
#if defined(TOOLKIT_GTK)
#include <gtk/gtk.h>
#include "ui/base/gtk/gtk_signal.h"
typedef struct _GtkToolItem GtkToolItem;
#elif defined(OS_ANDROID)
#include "base/android/scoped_java_ref.h"
#elif defined(USE_AURA)
namespace views {
class Widget;
class ViewsDelegate;
}
namespace aura {
namespace client {
class StackingClient;
}
}
#endif
class GURL;
namespace content {
class BrowserContext;
class ShellJavaScriptDialogCreator;
class SiteInstance;
class WebContents;
class Shell : public WebContentsDelegate,
public NotificationObserver {
public:
virtual ~Shell();
void LoadURL(const GURL& url);
void GoBackOrForward(int offset);
void Reload();
void Stop();
void UpdateNavigationControls();
void Close();
void ShowDevTools();
static void PlatformInitialize();
static Shell* CreateNewWindow(BrowserContext* browser_context,
const GURL& url,
SiteInstance* site_instance,
int routing_id,
WebContents* base_web_contents);
static Shell* FromRenderViewHost(RenderViewHost* rvh);
static std::vector<Shell*>& windows() { return windows_; }
static void CloseAllWindows();
static void PlatformExit();
static void SetShellCreatedCallback(
base::Callback<void(Shell*)> shell_created_callback);
WebContents* web_contents() const { return web_contents_.get(); }
gfx::NativeWindow window() { return window_; }
#if defined(OS_MACOSX)
void ActionPerformed(int control);
void URLEntered(std::string url_string);
#elif defined(OS_ANDROID)
static bool Register(JNIEnv* env);
#endif
virtual WebContents* OpenURLFromTab(WebContents* source,
const OpenURLParams& params) OVERRIDE;
virtual void LoadingStateChanged(WebContents* source) OVERRIDE;
#if defined(OS_ANDROID)
virtual void LoadProgressChanged(WebContents* source,
double progress) OVERRIDE;
virtual void AttachLayer(WebContents* web_contents,
WebKit::WebLayer* layer) OVERRIDE;
virtual void RemoveLayer(WebContents* web_contents,
WebKit::WebLayer* layer) OVERRIDE;
#endif
virtual void CloseContents(WebContents* source) OVERRIDE;
virtual void WebContentsCreated(WebContents* source_contents,
int64 source_frame_id,
const GURL& target_url,
WebContents* new_contents) OVERRIDE;
virtual void DidNavigateMainFramePostCommit(
WebContents* web_contents) OVERRIDE;
virtual JavaScriptDialogCreator* GetJavaScriptDialogCreator() OVERRIDE;
#if defined(OS_MACOSX)
virtual void HandleKeyboardEvent(
WebContents* source,
const NativeWebKeyboardEvent& event) OVERRIDE;
#endif
virtual bool AddMessageToConsole(WebContents* source,
int32 level,
const string16& message,
int32 line_no,
const string16& source_id) OVERRIDE;
virtual void RendererUnresponsive(WebContents* source) OVERRIDE;
private:
enum UIControl {
BACK_BUTTON,
FORWARD_BUTTON,
STOP_BUTTON
};
explicit Shell(WebContents* web_contents);
static Shell* CreateShell(WebContents* web_contents);
void PlatformCleanUp();
void PlatformCreateWindow(int width, int height);
void PlatformSetContents();
void PlatformResizeSubViews();
void PlatformEnableUIControl(UIControl control, bool is_enabled);
void PlatformSetAddressBarURL(const GURL& url);
void PlatformSetIsLoading(bool loading);
void PlatformSetTitle(const string16& title);
#if (defined(OS_WIN) && !defined(USE_AURA)) || defined(TOOLKIT_GTK)
void SizeTo(int width, int height);
#endif
gfx::NativeView GetContentView();
virtual void Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) OVERRIDE;
#if defined(OS_WIN) && !defined(USE_AURA)
static ATOM RegisterWindowClass();
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK EditWndProc(HWND, UINT, WPARAM, LPARAM);
#elif defined(TOOLKIT_GTK)
CHROMEGTK_CALLBACK_0(Shell, void, OnBackButtonClicked);
CHROMEGTK_CALLBACK_0(Shell, void, OnForwardButtonClicked);
CHROMEGTK_CALLBACK_0(Shell, void, OnReloadButtonClicked);
CHROMEGTK_CALLBACK_0(Shell, void, OnStopButtonClicked);
CHROMEGTK_CALLBACK_0(Shell, void, OnURLEntryActivate);
CHROMEGTK_CALLBACK_0(Shell, gboolean, OnWindowDestroyed);
CHROMEG_CALLBACK_3(Shell, gboolean, OnCloseWindowKeyPressed, GtkAccelGroup*,
GObject*, guint, GdkModifierType);
CHROMEG_CALLBACK_3(Shell, gboolean, OnNewWindowKeyPressed, GtkAccelGroup*,
GObject*, guint, GdkModifierType);
CHROMEG_CALLBACK_3(Shell, gboolean, OnHighlightURLView, GtkAccelGroup*,
GObject*, guint, GdkModifierType);
#endif
scoped_ptr<ShellJavaScriptDialogCreator> dialog_creator_;
scoped_ptr<WebContents> web_contents_;
gfx::NativeWindow window_;
gfx::NativeEditView url_edit_view_;
NotificationRegistrar registrar_;
#if defined(OS_WIN) && !defined(USE_AURA)
WNDPROC default_edit_wnd_proc_;
static HINSTANCE instance_handle_;
#elif defined(TOOLKIT_GTK)
GtkWidget* vbox_;
GtkToolItem* back_button_;
GtkToolItem* forward_button_;
GtkToolItem* reload_button_;
GtkToolItem* stop_button_;
GtkWidget* spinner_;
GtkToolItem* spinner_item_;
int content_width_;
int content_height_;
#elif defined(OS_ANDROID)
base::android::ScopedJavaGlobalRef<jobject> java_object_;
#elif defined(USE_AURA)
static aura::client::StackingClient* stacking_client_;
static views::ViewsDelegate* views_delegate_;
views::Widget* window_widget_;
#endif
static std::vector<Shell*> windows_;
static base::Callback<void(Shell*)> shell_created_callback_;
static bool quit_message_loop_;
};
}
#endif