Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/browser/ui/views/external_tab_container_win.cc

Issue 12220101: Minimal Chrome Frame with Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed inclusion of web_contents_view.h from automation_provider_win.h. see patch set 5 for trybot… Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/external_tab_container_win.h" 5 #include "chrome/browser/ui/views/external_tab_container_win.h"
6 6
7 #include <atlbase.h>
8 #include <atlapp.h>
9 #include <atlconv.h>
10 #include <atlmisc.h>
7 #include <string> 11 #include <string>
8 12
9 #include "base/bind.h" 13 #include "base/bind.h"
10 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
11 #include "base/debug/trace_event.h" 15 #include "base/debug/trace_event.h"
12 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
13 #include "base/logging.h" 17 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
15 #include "base/string16.h" 19 #include "base/string16.h"
16 #include "base/time.h" 20 #include "base/time.h"
(...skipping 12 matching lines...) Expand all
29 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/repost_form_warning_controller.h" 34 #include "chrome/browser/repost_form_warning_controller.h"
31 #include "chrome/browser/themes/theme_properties.h" 35 #include "chrome/browser/themes/theme_properties.h"
32 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h" 36 #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h"
33 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 37 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
34 #include "chrome/browser/ui/browser.h" 38 #include "chrome/browser/ui/browser.h"
35 #include "chrome/browser/ui/browser_tab_contents.h" 39 #include "chrome/browser/ui/browser_tab_contents.h"
36 #include "chrome/browser/ui/browser_window.h" 40 #include "chrome/browser/ui/browser_window.h"
37 #include "chrome/browser/ui/media_stream_infobar_delegate.h" 41 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
38 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" 42 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
43 #include "chrome/browser/ui/views/hwnd_util.h"
39 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" 44 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
40 #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_win.h" 45 #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_win.h"
41 #include "chrome/common/automation_messages.h" 46 #include "chrome/common/automation_messages.h"
42 #include "chrome/common/chrome_constants.h" 47 #include "chrome/common/chrome_constants.h"
43 #include "chrome/common/chrome_notification_types.h" 48 #include "chrome/common/chrome_notification_types.h"
44 #include "chrome/common/render_messages.h" 49 #include "chrome/common/render_messages.h"
45 #include "chrome/common/url_constants.h" 50 #include "chrome/common/url_constants.h"
46 #include "content/public/browser/load_notification_details.h" 51 #include "content/public/browser/load_notification_details.h"
47 #include "content/public/browser/native_web_keyboard_event.h" 52 #include "content/public/browser/native_web_keyboard_event.h"
48 #include "content/public/browser/navigation_details.h" 53 #include "content/public/browser/navigation_details.h"
(...skipping 14 matching lines...) Expand all
63 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" 68 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h"
64 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h " 69 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h "
65 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" 70 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
66 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 71 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
67 #include "ui/base/events/event_utils.h" 72 #include "ui/base/events/event_utils.h"
68 #include "ui/base/l10n/l10n_util.h" 73 #include "ui/base/l10n/l10n_util.h"
69 #include "ui/base/models/menu_model.h" 74 #include "ui/base/models/menu_model.h"
70 #include "ui/base/view_prop.h" 75 #include "ui/base/view_prop.h"
71 #include "ui/views/controls/webview/webview.h" 76 #include "ui/views/controls/webview/webview.h"
72 #include "ui/views/layout/grid_layout.h" 77 #include "ui/views/layout/grid_layout.h"
73 #include "ui/views/win/hwnd_message_handler.h" 78 #include "ui/views/widget/widget.h"
79
80 #if defined(USE_AURA)
81 #include "ui/aura/root_window.h"
82 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
83 #endif
74 84
75 using content::BrowserThread; 85 using content::BrowserThread;
76 using content::LoadNotificationDetails; 86 using content::LoadNotificationDetails;
77 using content::NativeWebKeyboardEvent; 87 using content::NativeWebKeyboardEvent;
78 using content::NavigationController; 88 using content::NavigationController;
79 using content::NavigationEntry; 89 using content::NavigationEntry;
80 using content::OpenURLParams; 90 using content::OpenURLParams;
81 using content::RenderViewHost; 91 using content::RenderViewHost;
82 using content::SSLStatus; 92 using content::SSLStatus;
83 using content::WebContents; 93 using content::WebContents;
84 using ui::ViewProp;
85 using WebKit::WebCString; 94 using WebKit::WebCString;
86 using WebKit::WebReferrerPolicy; 95 using WebKit::WebReferrerPolicy;
87 using WebKit::WebSecurityPolicy; 96 using WebKit::WebSecurityPolicy;
88 using WebKit::WebString; 97 using WebKit::WebString;
89 98
99 namespace {
100
90 static const char kWindowObjectKey[] = "ChromeWindowObject"; 101 static const char kWindowObjectKey[] = "ChromeWindowObject";
91 102
92 namespace { 103 // The following helper functions exist to localize UI toolkik-specific code.
robertshield 2013/02/27 21:15:42 kik -> kit
grt (UTC plus 2) 2013/02/28 02:48:41 Done.
104
105 void ShowNativeView(gfx::NativeView view) {
106 #if !defined(USE_AURA)
107 ::ShowWindow(view, SW_SHOWNA);
108 #endif
109 }
110
111 scoped_ptr<content::NativeWebKeyboardEvent> CreateKeyboardEvent(
112 const MSG& msg) {
113 #if defined(USE_AURA)
114 // TODO(grt): confirm that this is a translated character event.
115 ui::KeyEvent key_event(msg, true);
116 return scoped_ptr<content::NativeWebKeyboardEvent>(
117 new content::NativeWebKeyboardEvent(&key_event));
118 #else
119 return scoped_ptr<content::NativeWebKeyboardEvent>(
120 new content::NativeWebKeyboardEvent(msg));
121 #endif
122 }
123
124 const MSG& MessageFromKeyboardEvent(
125 const content::NativeWebKeyboardEvent& event) {
126 #if defined(USE_AURA)
127 return event.os_event->native_event();
128 #else
129 return event.os_event;
130 #endif
131 }
93 132
94 // Convert ui::MenuModel into a serializable form for Chrome Frame 133 // Convert ui::MenuModel into a serializable form for Chrome Frame
95 ContextMenuModel* ConvertMenuModel(const ui::MenuModel* ui_model) { 134 ContextMenuModel* ConvertMenuModel(const ui::MenuModel* ui_model) {
96 ContextMenuModel* new_model = new ContextMenuModel; 135 ContextMenuModel* new_model = new ContextMenuModel;
97 136
98 const int item_count = ui_model->GetItemCount(); 137 const int item_count = ui_model->GetItemCount();
99 new_model->items.reserve(item_count); 138 new_model->items.reserve(item_count);
100 for (int i = 0; i < item_count; ++i) { 139 for (int i = 0; i < item_count; ++i) {
101 if (ui_model->IsVisibleAt(i)) { 140 if (ui_model->IsVisibleAt(i)) {
102 ContextMenuModel::Item item; 141 ContextMenuModel::Item item;
(...skipping 13 matching lines...) Expand all
116 } 155 }
117 156
118 } // namespace 157 } // namespace
119 158
120 base::LazyInstance<ExternalTabContainerWin::PendingTabs> 159 base::LazyInstance<ExternalTabContainerWin::PendingTabs>
121 ExternalTabContainerWin::pending_tabs_ = LAZY_INSTANCE_INITIALIZER; 160 ExternalTabContainerWin::pending_tabs_ = LAZY_INSTANCE_INITIALIZER;
122 161
123 ExternalTabContainerWin::ExternalTabContainerWin( 162 ExternalTabContainerWin::ExternalTabContainerWin(
124 AutomationProvider* automation, 163 AutomationProvider* automation,
125 AutomationResourceMessageFilter* filter) 164 AutomationResourceMessageFilter* filter)
126 : views::NativeWidgetWin(new views::Widget), 165 : widget_(NULL),
127 automation_(automation), 166 automation_(automation),
128 tab_contents_container_(NULL), 167 tab_contents_container_(NULL),
129 tab_handle_(0), 168 tab_handle_(0),
130 ignore_next_load_notification_(false), 169 ignore_next_load_notification_(false),
131 automation_resource_message_filter_(filter), 170 automation_resource_message_filter_(filter),
132 load_requests_via_automation_(false), 171 load_requests_via_automation_(false),
133 handle_top_level_requests_(false), 172 handle_top_level_requests_(false),
173 route_all_top_level_navigations_(false),
robertshield 2013/02/27 21:15:42 just curious, was there a functional reason to cha
grt (UTC plus 2) 2013/02/28 02:48:41 Mostly just for style: when I see three bool membe
134 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 174 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
135 pending_(false), 175 pending_(false),
136 focus_manager_(NULL), 176 focus_manager_(NULL),
137 external_tab_view_(NULL), 177 external_tab_view_(NULL),
138 unload_reply_message_(NULL), 178 unload_reply_message_(NULL),
139 route_all_top_level_navigations_(false),
140 is_popup_window_(false) { 179 is_popup_window_(false) {
141 } 180 }
142 181
143 // static 182 // static
144 scoped_refptr<ExternalTabContainer> 183 scoped_refptr<ExternalTabContainer>
145 ExternalTabContainerWin::RemovePendingExternalTab(uintptr_t cookie) { 184 ExternalTabContainerWin::RemovePendingExternalTab(uintptr_t cookie) {
146 PendingTabs& pending_tabs = pending_tabs_.Get(); 185 PendingTabs& pending_tabs = pending_tabs_.Get();
147 PendingTabs::iterator index = pending_tabs.find(cookie); 186 PendingTabs::iterator index = pending_tabs.find(cookie);
148 if (index != pending_tabs.end()) { 187 if (index != pending_tabs.end()) {
149 scoped_refptr<ExternalTabContainer> container = (*index).second; 188 scoped_refptr<ExternalTabContainer> container = (*index).second;
(...skipping 10 matching lines...) Expand all
160 HWND parent, 199 HWND parent,
161 const gfx::Rect& bounds, 200 const gfx::Rect& bounds,
162 DWORD style, 201 DWORD style,
163 bool load_requests_via_automation, 202 bool load_requests_via_automation,
164 bool handle_top_level_requests, 203 bool handle_top_level_requests,
165 content::WebContents* existing_contents, 204 content::WebContents* existing_contents,
166 const GURL& initial_url, 205 const GURL& initial_url,
167 const GURL& referrer, 206 const GURL& referrer,
168 bool infobars_enabled, 207 bool infobars_enabled,
169 bool route_all_top_level_navigations) { 208 bool route_all_top_level_navigations) {
170 if (IsWindow(GetNativeView())) { 209 if (widget_) {
171 NOTREACHED(); 210 NOTREACHED();
172 return false; 211 return false;
173 } 212 }
174 213
214 widget_ = new views::Widget();
215 widget_->AddObserver(this);
175 load_requests_via_automation_ = load_requests_via_automation; 216 load_requests_via_automation_ = load_requests_via_automation;
176 handle_top_level_requests_ = handle_top_level_requests; 217 handle_top_level_requests_ = handle_top_level_requests;
177 route_all_top_level_navigations_ = route_all_top_level_navigations; 218 route_all_top_level_navigations_ = route_all_top_level_navigations;
178 219
179 GetMessageHandler()->set_window_style(WS_POPUP | WS_CLIPCHILDREN);
180
181 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 220 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
182 params.bounds = bounds; 221 params.bounds = bounds;
183 params.native_widget = this; 222 #if defined(USE_AURA)
184 GetWidget()->Init(params); 223 params.native_widget = new views::DesktopNativeWidgetAura(widget_);
185 if (!IsWindow(GetNativeView())) { 224 #endif
186 NOTREACHED(); 225 widget_->Init(params);
187 return false; 226 HWND window = chrome::HWNDForWidget(widget_);
188 }
189 227
190 // TODO(jcampan): limit focus traversal to contents. 228 // TODO(jcampan): limit focus traversal to contents.
191 229
192 prop_.reset(new ViewProp(GetNativeView(), kWindowObjectKey, this)); 230 prop_.reset(new ui::ViewProp(window, kWindowObjectKey, this));
193 231
194 if (existing_contents) { 232 if (existing_contents) {
195 existing_contents->GetController().SetBrowserContext(profile); 233 existing_contents->GetController().SetBrowserContext(profile);
196 } else { 234 } else {
197 existing_contents = WebContents::Create(WebContents::CreateParams(profile)); 235 existing_contents = WebContents::Create(WebContents::CreateParams(profile));
198 existing_contents->GetRenderViewHost()->AllowBindings( 236 existing_contents->GetRenderViewHost()->AllowBindings(
199 content::BINDINGS_POLICY_EXTERNAL_HOST); 237 content::BINDINGS_POLICY_EXTERNAL_HOST);
200 } 238 }
201 239
202 existing_contents->SetDelegate(this); 240 existing_contents->SetDelegate(this);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 weak_factory_.GetWeakPtr(), 274 weak_factory_.GetWeakPtr(),
237 initial_url, referrer)); 275 initial_url, referrer));
238 } 276 }
239 277
240 // We need WS_POPUP to be on the window during initialization, but 278 // We need WS_POPUP to be on the window during initialization, but
241 // once initialized we apply the requested style which may or may not 279 // once initialized we apply the requested style which may or may not
242 // include the popup bit. 280 // include the popup bit.
243 // Note that it's important to do this before we call SetParent since 281 // Note that it's important to do this before we call SetParent since
244 // during the SetParent call we will otherwise get a WA_ACTIVATE call 282 // during the SetParent call we will otherwise get a WA_ACTIVATE call
245 // that causes us to steal the current focus. 283 // that causes us to steal the current focus.
246 SetWindowLong( 284 SetWindowLong(window, GWL_STYLE,
247 GetNativeView(), GWL_STYLE, 285 (GetWindowLong(window, GWL_STYLE) & ~WS_POPUP) | style);
248 (GetWindowLong(GetNativeView(), GWL_STYLE) & ~WS_POPUP) | style);
249 286
250 // Now apply the parenting and style 287 // Now apply the parenting and style
251 if (parent) 288 if (parent)
252 SetParent(GetNativeView(), parent); 289 SetParent(window, parent);
253 290
254 ::ShowWindow(existing_contents->GetView()->GetNativeView(), SW_SHOWNA); 291 ShowNativeView(existing_contents->GetView()->GetNativeView());
255 292
256 LoadAccelerators(); 293 LoadAccelerators();
257 SetupExternalTabView(); 294 SetupExternalTabView();
258 BlockedContentTabHelper::FromWebContents(existing_contents)-> 295 BlockedContentTabHelper::FromWebContents(existing_contents)->
259 set_delegate(this); 296 set_delegate(this);
260 return true; 297 return true;
261 } 298 }
262 299
263 void ExternalTabContainerWin::Uninitialize() { 300 void ExternalTabContainerWin::Uninitialize() {
264 registrar_.RemoveAll(); 301 registrar_.RemoveAll();
265 if (web_contents_.get()) { 302 if (web_contents_.get()) {
303 tab_contents_container_->SetWebContents(NULL);
266 UnregisterRenderViewHost(web_contents_->GetRenderViewHost()); 304 UnregisterRenderViewHost(web_contents_->GetRenderViewHost());
267 305
268 // Explicitly tell the RPH to shutdown, as doing so is the only thing that 306 // Explicitly tell the RPH to shutdown, as doing so is the only thing that
269 // cleans up certain resources like infobars (crbug.com/148398). 307 // cleans up certain resources like infobars (crbug.com/148398).
270 // Tell the RPH to shutdown iff it has a page count of 1, meaning that 308 // Tell the RPH to shutdown iff it has a page count of 1, meaning that
271 // there is only a single remaining render widget host (the one owned by 309 // there is only a single remaining render widget host (the one owned by
272 // web_contents_) using this RPH. 310 // web_contents_) using this RPH.
273 // 311 //
274 // Note that it is not possible to simply call FastShutdownIfPossible on the 312 // Note that it is not possible to simply call FastShutdownIfPossible on the
275 // RPH here as that unfortunately ignores RPH's internal ref count, which 313 // RPH here as that unfortunately ignores RPH's internal ref count, which
276 // leaves any other render widget hosts using the same RPH dangling. 314 // leaves any other render widget hosts using the same RPH dangling.
277 // 315 //
278 // Note that in an ideal world, this would not be needed. The WebContents 316 // Note that in an ideal world, this would not be needed. The WebContents
279 // could just destroy itself, resulting in RPH::Release() eventually getting 317 // could just destroy itself, resulting in RPH::Release() eventually getting
280 // called and all would be neat and tidy. Sadly, the RPH only fires 318 // called and all would be neat and tidy. Sadly, the RPH only fires
281 // NOTIFICATION_RENDERER_PROCESS_CLOSED if one of the FastShutdownXXX 319 // NOTIFICATION_RENDERER_PROCESS_CLOSED if one of the FastShutdownXXX
282 // methods is called and other components rely on that notification to avoid 320 // methods is called and other components rely on that notification to avoid
283 // crashing on shutdown. Sad panda. Or maybe clinically depressed panda is 321 // crashing on shutdown. Sad panda. Or maybe clinically depressed panda is
284 // more fitting. 322 // more fitting.
285 web_contents_->GetRenderProcessHost()->FastShutdownForPageCount(1); 323 web_contents_->GetRenderProcessHost()->FastShutdownForPageCount(1);
286 324
287 if (GetWidget()->GetRootView()) 325 if (widget_->GetRootView())
288 GetWidget()->GetRootView()->RemoveAllChildViews(true); 326 widget_->GetRootView()->RemoveAllChildViews(true);
327 widget_ = NULL;
289 328
290 content::NotificationService::current()->Notify( 329 content::NotificationService::current()->Notify(
291 chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, 330 chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED,
292 content::Source<NavigationController>(&web_contents_->GetController()), 331 content::Source<NavigationController>(&web_contents_->GetController()),
293 content::Details<ExternalTabContainer>(this)); 332 content::Details<ExternalTabContainer>(this));
294 333
295 web_contents_.reset(NULL); 334 web_contents_.reset(NULL);
296 } 335 }
297 336
298 if (focus_manager_) { 337 if (focus_manager_) {
299 focus_manager_->UnregisterAccelerators(this); 338 focus_manager_->UnregisterAccelerators(this);
300 focus_manager_ = NULL; 339 focus_manager_ = NULL;
301 } 340 }
302 341
303 external_tab_view_ = NULL; 342 external_tab_view_ = NULL;
304 request_context_ = NULL; 343 request_context_ = NULL;
305 tab_contents_container_ = NULL; 344 tab_contents_container_ = NULL;
306 } 345 }
307 346
308 bool ExternalTabContainerWin::Reinitialize( 347 bool ExternalTabContainerWin::Reinitialize(
309 AutomationProvider* automation_provider, 348 AutomationProvider* automation_provider,
310 AutomationResourceMessageFilter* filter, 349 AutomationResourceMessageFilter* filter,
311 gfx::NativeWindow parent_window) { 350 HWND parent_window) {
312 if (!automation_provider || !filter) { 351 if (!automation_provider || !filter) {
313 NOTREACHED(); 352 NOTREACHED();
314 return false; 353 return false;
315 } 354 }
316 355
317 automation_ = automation_provider; 356 automation_ = automation_provider;
318 automation_resource_message_filter_ = filter; 357 automation_resource_message_filter_ = filter;
319 // Wait for the automation channel to be initialized before resuming pending 358 // Wait for the automation channel to be initialized before resuming pending
320 // render views and sending in the navigation state. 359 // render views and sending in the navigation state.
321 MessageLoop::current()->PostTask( 360 MessageLoop::current()->PostTask(
322 FROM_HERE, base::Bind(&ExternalTabContainerWin::OnReinitialize, 361 FROM_HERE, base::Bind(&ExternalTabContainerWin::OnReinitialize,
323 weak_factory_.GetWeakPtr())); 362 weak_factory_.GetWeakPtr()));
324 363
325 if (parent_window) 364 if (parent_window)
326 SetParent(GetNativeView(), parent_window); 365 SetParent(chrome::HWNDForWidget(widget_), parent_window);
robertshield 2013/02/27 21:15:42 should this, and other occurrences of this call be
grt (UTC plus 2) 2013/02/28 02:48:41 That would certainly work, but I don't like that i
327 return true; 366 return true;
328 } 367 }
329 368
330 WebContents* ExternalTabContainerWin::GetWebContents() const { 369 WebContents* ExternalTabContainerWin::GetWebContents() const {
331 return web_contents_.get(); 370 return web_contents_.get();
332 } 371 }
333 372
334 gfx::NativeView ExternalTabContainerWin::GetExternalTabNativeView() const { 373 HWND ExternalTabContainerWin::GetExternalTabHWND() const {
335 return GetNativeView(); 374 return chrome::HWNDForWidget(widget_);
375 }
376
377 HWND ExternalTabContainerWin::GetContentHWND() const {
378 return chrome::HWNDForNativeWindow(web_contents_->GetView()->GetNativeView());
336 } 379 }
337 380
338 void ExternalTabContainerWin::SetTabHandle(int handle) { 381 void ExternalTabContainerWin::SetTabHandle(int handle) {
339 tab_handle_ = handle; 382 tab_handle_ = handle;
340 } 383 }
341 384
342 int ExternalTabContainerWin::GetTabHandle() const { 385 int ExternalTabContainerWin::GetTabHandle() const {
343 return tab_handle_; 386 return tab_handle_;
344 } 387 }
345 388
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 web_contents_.get() && 425 web_contents_.get() &&
383 Browser::RunUnloadEventsHelper(web_contents_.get()); 426 Browser::RunUnloadEventsHelper(web_contents_.get());
384 if (!wait_for_unload_handlers) { 427 if (!wait_for_unload_handlers) {
385 AutomationMsg_RunUnloadHandlers::WriteReplyParams(reply_message, true); 428 AutomationMsg_RunUnloadHandlers::WriteReplyParams(reply_message, true);
386 automation_->Send(reply_message); 429 automation_->Send(reply_message);
387 unload_reply_message_ = NULL; 430 unload_reply_message_ = NULL;
388 } 431 }
389 } 432 }
390 433
391 void ExternalTabContainerWin::ProcessUnhandledAccelerator(const MSG& msg) { 434 void ExternalTabContainerWin::ProcessUnhandledAccelerator(const MSG& msg) {
392 NativeWebKeyboardEvent keyboard_event(msg); 435 scoped_ptr<NativeWebKeyboardEvent> keyboard_event(CreateKeyboardEvent(msg));
393 unhandled_keyboard_event_handler_.HandleKeyboardEvent(keyboard_event, 436 unhandled_keyboard_event_handler_.HandleKeyboardEvent(*keyboard_event,
394 focus_manager_); 437 focus_manager_);
395 } 438 }
396 439
397 void ExternalTabContainerWin::FocusThroughTabTraversal( 440 void ExternalTabContainerWin::FocusThroughTabTraversal(
398 bool reverse, 441 bool reverse,
399 bool restore_focus_to_view) { 442 bool restore_focus_to_view) {
400 DCHECK(web_contents_.get()); 443 DCHECK(web_contents_.get());
401 if (web_contents_.get()) 444 if (web_contents_.get())
402 web_contents_->GetView()->Focus(); 445 web_contents_->GetView()->Focus();
403 446
404 // The web_contents_ member can get destroyed in the context of the call to 447 // The web_contents_ member can get destroyed in the context of the call to
405 // WebContentsViewViews::Focus() above. This method eventually calls SetFocus 448 // WebContentsViewViews::Focus() above. This method eventually calls SetFocus
406 // on the native window, which could end up dispatching messages like 449 // on the native window, which could end up dispatching messages like
407 // WM_DESTROY for the external tab. 450 // WM_DESTROY for the external tab.
408 if (web_contents_.get() && restore_focus_to_view) 451 if (web_contents_.get() && restore_focus_to_view)
409 web_contents_->FocusThroughTabTraversal(reverse); 452 web_contents_->FocusThroughTabTraversal(reverse);
410 } 453 }
411 454
412 // static
413 bool ExternalTabContainerWin::IsExternalTabContainer(HWND window) {
414 return ViewProp::GetValue(window, kWindowObjectKey) != NULL;
415 }
416
417 // static
418 ExternalTabContainer*
419 ExternalTabContainerWin::GetExternalContainerFromNativeWindow(
420 gfx::NativeView native_window) {
421 ExternalTabContainer* tab_container = NULL;
422 if (native_window) {
423 tab_container = reinterpret_cast<ExternalTabContainer*>(
424 ViewProp::GetValue(native_window, kWindowObjectKey));
425 }
426 return tab_container;
427 }
428 //////////////////////////////////////////////////////////////////////////////// 455 ////////////////////////////////////////////////////////////////////////////////
429 // ExternalTabContainer, content::WebContentsDelegate implementation: 456 // ExternalTabContainer, content::WebContentsDelegate implementation:
430 457
431 WebContents* ExternalTabContainerWin::OpenURLFromTab( 458 WebContents* ExternalTabContainerWin::OpenURLFromTab(
432 WebContents* source, 459 WebContents* source,
433 const OpenURLParams& params) { 460 const OpenURLParams& params) {
434 if (pending()) { 461 if (pending()) {
435 pending_open_url_requests_.push_back(params); 462 pending_open_url_requests_.push_back(params);
436 return NULL; 463 return NULL;
437 } 464 }
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 web_contents(), params)); 739 web_contents(), params));
713 static_cast<RenderViewContextMenuWin*>( 740 static_cast<RenderViewContextMenuWin*>(
714 external_context_menu_.get())->SetExternal(); 741 external_context_menu_.get())->SetExternal();
715 external_context_menu_->Init(); 742 external_context_menu_->Init();
716 external_context_menu_->UpdateMenuItemStates(); 743 external_context_menu_->UpdateMenuItemStates();
717 744
718 scoped_ptr<ContextMenuModel> context_menu_model( 745 scoped_ptr<ContextMenuModel> context_menu_model(
719 ConvertMenuModel(&external_context_menu_->menu_model())); 746 ConvertMenuModel(&external_context_menu_->menu_model()));
720 747
721 POINT screen_pt = { params.x, params.y }; 748 POINT screen_pt = { params.x, params.y };
722 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); 749 MapWindowPoints(chrome::HWNDForWidget(widget_), HWND_DESKTOP, &screen_pt, 1);
723 750
724 MiniContextMenuParams ipc_params; 751 MiniContextMenuParams ipc_params;
725 ipc_params.screen_x = screen_pt.x; 752 ipc_params.screen_x = screen_pt.x;
726 ipc_params.screen_y = screen_pt.y; 753 ipc_params.screen_y = screen_pt.y;
727 ipc_params.link_url = params.link_url; 754 ipc_params.link_url = params.link_url;
728 ipc_params.unfiltered_link_url = params.unfiltered_link_url; 755 ipc_params.unfiltered_link_url = params.unfiltered_link_url;
729 ipc_params.src_url = params.src_url; 756 ipc_params.src_url = params.src_url;
730 ipc_params.page_url = params.page_url; 757 ipc_params.page_url = params.page_url;
731 ipc_params.keyword_url = params.keyword_url; 758 ipc_params.keyword_url = params.keyword_url;
732 ipc_params.frame_url = params.frame_url; 759 ipc_params.frame_url = params.frame_url;
(...skipping 10 matching lines...) Expand all
743 bool ExternalTabContainerWin::PreHandleKeyboardEvent( 770 bool ExternalTabContainerWin::PreHandleKeyboardEvent(
744 content::WebContents* source, 771 content::WebContents* source,
745 const NativeWebKeyboardEvent& event, 772 const NativeWebKeyboardEvent& event,
746 bool* is_keyboard_shortcut) { 773 bool* is_keyboard_shortcut) {
747 return false; 774 return false;
748 } 775 }
749 776
750 void ExternalTabContainerWin::HandleKeyboardEvent( 777 void ExternalTabContainerWin::HandleKeyboardEvent(
751 content::WebContents* source, 778 content::WebContents* source,
752 const NativeWebKeyboardEvent& event) { 779 const NativeWebKeyboardEvent& event) {
753 ProcessUnhandledKeyStroke(event.os_event.hwnd, event.os_event.message, 780 const MSG& message = MessageFromKeyboardEvent(event);
754 event.os_event.wParam, event.os_event.lParam); 781 ProcessUnhandledKeyStroke(message.hwnd, message.message,
782 message.wParam, message.lParam);
755 } 783 }
756 784
757 void ExternalTabContainerWin::BeforeUnloadFired(WebContents* tab, 785 void ExternalTabContainerWin::BeforeUnloadFired(WebContents* tab,
758 bool proceed, 786 bool proceed,
759 bool* proceed_to_fire_unload) { 787 bool* proceed_to_fire_unload) {
760 *proceed_to_fire_unload = true; 788 *proceed_to_fire_unload = true;
761 789
762 if (!automation_) { 790 if (!automation_) {
763 delete unload_reply_message_; 791 delete unload_reply_message_;
764 unload_reply_message_ = NULL; 792 unload_reply_message_ = NULL;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 RegisterRenderViewHostForAutomation(rvh, false); 971 RegisterRenderViewHostForAutomation(rvh, false);
944 } 972 }
945 break; 973 break;
946 } 974 }
947 default: 975 default:
948 NOTREACHED(); 976 NOTREACHED();
949 } 977 }
950 } 978 }
951 979
952 //////////////////////////////////////////////////////////////////////////////// 980 ////////////////////////////////////////////////////////////////////////////////
953 // ExternalTabContainer, views::NativeWidgetWin overrides: 981 // WidgetObserver overrides:
954 982
955 bool ExternalTabContainerWin::PreHandleMSG(UINT message, 983 void ExternalTabContainerWin::OnWidgetCreated(views::Widget* widget) {
956 WPARAM w_param, 984 DCHECK_EQ(widget_, widget);
957 LPARAM l_param, 985 // Grab a reference here which will be released in OnWidgetDestroyed.
958 LRESULT* result) { 986 AddRef();
959 if (message == WM_DESTROY) {
960 prop_.reset();
961 Uninitialize();
962 }
963 return false;
964 } 987 }
965 988
966 void ExternalTabContainerWin::PostHandleMSG(UINT message, 989 void ExternalTabContainerWin::OnWidgetDestroying(views::Widget* widget) {
967 WPARAM w_param, 990 DCHECK_EQ(widget_, widget);
968 LPARAM l_param) { 991 Uninitialize();
969 // Grab a reference here which will be released in OnFinalMessage 992 prop_.reset();
970 if (message == WM_CREATE)
971 AddRef();
972 } 993 }
973 994
974 void ExternalTabContainerWin::OnFinalMessage(HWND window) { 995 void ExternalTabContainerWin::OnWidgetDestroyed(views::Widget* widget) {
975 GetWidget()->OnNativeWidgetDestroyed(); 996 DCHECK_EQ(widget_, static_cast<views::Widget*>(NULL));
976 // Release the reference which we grabbed in WM_CREATE. 997 // Release the reference which we grabbed in OnWidgetCreated.
977 Release(); 998 Release();
978 } 999 }
979 1000
980 //////////////////////////////////////////////////////////////////////////////// 1001 ////////////////////////////////////////////////////////////////////////////////
981 // ExternalTabContainer, private: 1002 // ExternalTabContainer, private:
982 bool ExternalTabContainerWin::ProcessUnhandledKeyStroke(HWND window, 1003 bool ExternalTabContainerWin::ProcessUnhandledKeyStroke(HWND window,
983 UINT message, 1004 UINT message,
984 WPARAM wparam, 1005 WPARAM wparam,
985 LPARAM lparam) { 1006 LPARAM lparam) {
986 if (!automation_) { 1007 if (!automation_) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 // Nothing to do in that case. 1158 // Nothing to do in that case.
1138 return; 1159 return;
1139 } 1160 }
1140 1161
1141 scoped_array<ACCEL> scoped_accelerators(new ACCEL[count]); 1162 scoped_array<ACCEL> scoped_accelerators(new ACCEL[count]);
1142 ACCEL* accelerators = scoped_accelerators.get(); 1163 ACCEL* accelerators = scoped_accelerators.get();
1143 DCHECK(accelerators != NULL); 1164 DCHECK(accelerators != NULL);
1144 1165
1145 CopyAcceleratorTable(accelerator_table, accelerators, count); 1166 CopyAcceleratorTable(accelerator_table, accelerators, count);
1146 1167
1147 focus_manager_ = GetWidget()->GetFocusManager(); 1168 focus_manager_ = widget_->GetFocusManager();
1148 DCHECK(focus_manager_); 1169 DCHECK(focus_manager_);
1149 1170
1150 // Let's fill our own accelerator table. 1171 // Let's fill our own accelerator table.
1151 for (int i = 0; i < count; ++i) { 1172 for (int i = 0; i < count; ++i) {
1152 ui::Accelerator accelerator( 1173 ui::Accelerator accelerator(
1153 static_cast<ui::KeyboardCode>(accelerators[i].key), 1174 static_cast<ui::KeyboardCode>(accelerators[i].key),
1154 ui::GetModifiersFromACCEL(accelerators[i])); 1175 ui::GetModifiersFromACCEL(accelerators[i]));
1155 accelerator_table_[accelerator] = accelerators[i].cmd; 1176 accelerator_table_[accelerator] = accelerators[i].cmd;
1156 1177
1157 // Also register with the focus manager. 1178 // Also register with the focus manager.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 views::GridLayout::USE_PREF, 1236 views::GridLayout::USE_PREF,
1216 0, 1237 0,
1217 0); 1238 0);
1218 1239
1219 external_tab_view_->SetLayoutManager(layout); 1240 external_tab_view_->SetLayoutManager(layout);
1220 1241
1221 layout->StartRow(0, 0); 1242 layout->StartRow(0, 0);
1222 layout->AddView(info_bar_container); 1243 layout->AddView(info_bar_container);
1223 layout->StartRow(1, 0); 1244 layout->StartRow(1, 0);
1224 layout->AddView(tab_contents_container_); 1245 layout->AddView(tab_contents_container_);
1225 GetWidget()->SetContentsView(external_tab_view_); 1246 widget_->SetContentsView(external_tab_view_);
1226 // Note that SetWebContents must be called after AddChildView is called 1247 // Note that SetWebContents must be called after AddChildView is called
1227 tab_contents_container_->SetWebContents(web_contents()); 1248 tab_contents_container_->SetWebContents(web_contents());
1228 } 1249 }
1229 1250
1230 // static 1251 // static
1231 ExternalTabContainer* ExternalTabContainer::Create( 1252 ExternalTabContainer* ExternalTabContainer::Create(
1232 AutomationProvider* automation_provider, 1253 AutomationProvider* automation_provider,
1233 AutomationResourceMessageFilter* filter) { 1254 AutomationResourceMessageFilter* filter) {
1234 return new ExternalTabContainerWin(automation_provider, filter); 1255 return new ExternalTabContainerWin(automation_provider, filter);
1235 } 1256 }
1236 1257
1237 // static 1258 // static
1238 ExternalTabContainer* ExternalTabContainer::GetContainerForTab( 1259 ExternalTabContainer* ExternalTabContainer::GetContainerForTab(
1239 HWND tab_window) { 1260 content::WebContents* web_contents) {
1240 HWND parent_window = ::GetParent(tab_window); 1261 HWND parent_window = chrome::HWNDForNativeWindow(
1241 if (!::IsWindow(parent_window)) { 1262 web_contents->GetView()->GetTopLevelNativeWindow());
1263 if (!::IsWindow(parent_window))
1242 return NULL; 1264 return NULL;
1243 } 1265 return reinterpret_cast<ExternalTabContainerWin*>(
1244 if (!ExternalTabContainerWin::IsExternalTabContainer(parent_window)) { 1266 ui::ViewProp::GetValue(parent_window, kWindowObjectKey));
1245 return NULL;
1246 }
1247 ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>(
1248 ViewProp::GetValue(parent_window, kWindowObjectKey));
1249 return container;
1250 } 1267 }
1251 1268
1252 // static 1269 // static
1253 scoped_refptr<ExternalTabContainer> ExternalTabContainer::RemovePendingTab( 1270 scoped_refptr<ExternalTabContainer> ExternalTabContainer::RemovePendingTab(
1254 uintptr_t cookie) { 1271 uintptr_t cookie) {
1255 return ExternalTabContainerWin::RemovePendingExternalTab(cookie); 1272 return ExternalTabContainerWin::RemovePendingExternalTab(cookie);
1256 } 1273 }
1257 1274
1258 /////////////////////////////////////////////////////////////////////////////// 1275 ///////////////////////////////////////////////////////////////////////////////
1259 // TemporaryPopupExternalTabContainerWin 1276 // TemporaryPopupExternalTabContainerWin
(...skipping 16 matching lines...) Expand all
1276 return NULL; 1293 return NULL;
1277 1294
1278 OpenURLParams forward_params = params; 1295 OpenURLParams forward_params = params;
1279 if (params.disposition == CURRENT_TAB) { 1296 if (params.disposition == CURRENT_TAB) {
1280 DCHECK(route_all_top_level_navigations_); 1297 DCHECK(route_all_top_level_navigations_);
1281 forward_params.disposition = NEW_FOREGROUND_TAB; 1298 forward_params.disposition = NEW_FOREGROUND_TAB;
1282 } 1299 }
1283 WebContents* new_contents = 1300 WebContents* new_contents =
1284 ExternalTabContainerWin::OpenURLFromTab(source, forward_params); 1301 ExternalTabContainerWin::OpenURLFromTab(source, forward_params);
1285 // support only one navigation for a dummy tab before it is killed. 1302 // support only one navigation for a dummy tab before it is killed.
1286 ::DestroyWindow(GetNativeView()); 1303 widget_->CloseNow();
1287 return new_contents; 1304 return new_contents;
1288 } 1305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698