1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_SHELL_SHELL_H_
#define CONTENT_SHELL_SHELL_H_
#pragma once
#include <vector>
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_piece.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/gfx/native_widget_types.h"
#if defined(OS_LINUX)
#include <gtk/gtk.h>
#include "ui/base/gtk/gtk_signal.h"
typedef struct _GtkToolItem GtkToolItem;
#endif
class GURL;
class TabContents;
namespace content {
class BrowserContext;
class SiteInstance;
// This represents one window of the Content Shell, i.e. all the UI including
// buttons and url bar, as well as the web content area.
class Shell : public WebContentsDelegate,
public WebContentsObserver {
public:
virtual ~Shell();
void LoadURL(const GURL& url);
void GoBackOrForward(int offset);
void Reload();
void Stop();
void UpdateNavigationControls();
// Do one time initialization at application startup.
static void PlatformInitialize();
// This is called indirectly by the modules that need access resources.
static base::StringPiece PlatformResourceProvider(int key);
static Shell* CreateNewWindow(content::BrowserContext* browser_context,
const GURL& url,
SiteInstance* site_instance,
int routing_id,
TabContents* base_tab_contents);
// Returns the Shell object corresponding to the given RenderViewHost.
static Shell* FromRenderViewHost(RenderViewHost* rvh);
// Closes all windows and exits.
static void PlatformExit();
TabContents* tab_contents() const { return tab_contents_.get(); }
// layoutTestController related methods.
void set_wait_until_done() { wait_until_done_ = true; }
#if defined(OS_MACOSX)
// Public to be called by an ObjC bridge object.
void ActionPerformed(int control);
void URLEntered(std::string url_string);
#endif
private:
enum UIControl {
BACK_BUTTON,
FORWARD_BUTTON,
STOP_BUTTON
};
explicit Shell(TabContents* tab_contents);
// Helper to create a new Shell given a newly created TabContents.
static Shell* CreateShell(TabContents* tab_contents);
// All the methods that begin with Platform need to be implemented by the
// platform specific Shell implementation.
// Called from the destructor to let each platform do any necessary cleanup.
void PlatformCleanUp();
// Creates the main window GUI.
void PlatformCreateWindow(int width, int height);
// Links the TabContents into the newly created window.
void PlatformSetContents();
// Resizes the main window to the given dimensions.
void PlatformSizeTo(int width, int height);
// Resize the content area and GUI.
void PlatformResizeSubViews();
// Enable/disable a button.
void PlatformEnableUIControl(UIControl control, bool is_enabled);
// Updates the url in the url bar.
void PlatformSetAddressBarURL(const GURL& url);
// Sets whether the spinner is spinning.
void PlatformSetIsLoading(bool loading);
gfx::NativeView GetContentView();
// content::WebContentsDelegate
virtual void LoadingStateChanged(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* tab) OVERRIDE;
virtual void UpdatePreferredSize(WebContents* source,
const gfx::Size& pref_size) OVERRIDE;
// content::WebContentsObserver
virtual void DidFinishLoad(int64 frame_id,
const GURL& validated_url,
bool is_main_frame) OVERRIDE;
#if defined(OS_WIN)
static ATOM RegisterWindowClass();
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK EditWndProc(HWND, UINT, WPARAM, LPARAM);
#elif defined(OS_LINUX)
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, OnHighlightURLView, GtkAccelGroup*,
GObject*, guint, GdkModifierType);
#endif
scoped_ptr<TabContents> tab_contents_;
// layoutTestController related variables.
bool wait_until_done_;
gfx::NativeWindow window_;
gfx::NativeEditView url_edit_view_;
#if defined(OS_WIN)
WNDPROC default_edit_wnd_proc_;
static HINSTANCE instance_handle_;
#elif defined(OS_LINUX)
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_;
#endif
// A container of all the open windows. We use a vector so we can keep track
// of ordering.
static std::vector<Shell*> windows_;
};
} // namespace content
#endif // CONTENT_SHELL_SHELL_H_
|