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

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: sync to r184453 Created 7 years, 10 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 27 matching lines...) Expand all
44 #include "chrome/common/render_messages.h" 48 #include "chrome/common/render_messages.h"
45 #include "chrome/common/url_constants.h" 49 #include "chrome/common/url_constants.h"
46 #include "content/public/browser/load_notification_details.h" 50 #include "content/public/browser/load_notification_details.h"
47 #include "content/public/browser/native_web_keyboard_event.h" 51 #include "content/public/browser/native_web_keyboard_event.h"
48 #include "content/public/browser/navigation_details.h" 52 #include "content/public/browser/navigation_details.h"
49 #include "content/public/browser/navigation_entry.h" 53 #include "content/public/browser/navigation_entry.h"
50 #include "content/public/browser/notification_service.h" 54 #include "content/public/browser/notification_service.h"
51 #include "content/public/browser/render_process_host.h" 55 #include "content/public/browser/render_process_host.h"
52 #include "content/public/browser/render_view_host.h" 56 #include "content/public/browser/render_view_host.h"
53 #include "content/public/browser/web_contents.h" 57 #include "content/public/browser/web_contents.h"
58 #include "content/public/browser/web_contents_view.h"
54 #include "content/public/common/bindings_policy.h" 59 #include "content/public/common/bindings_policy.h"
55 #include "content/public/common/frame_navigate_params.h" 60 #include "content/public/common/frame_navigate_params.h"
56 #include "content/public/common/page_transition_types.h" 61 #include "content/public/common/page_transition_types.h"
57 #include "content/public/common/page_zoom.h" 62 #include "content/public/common/page_zoom.h"
58 #include "content/public/common/renderer_preferences.h" 63 #include "content/public/common/renderer_preferences.h"
59 #include "content/public/common/ssl_status.h" 64 #include "content/public/common/ssl_status.h"
60 #include "grit/generated_resources.h" 65 #include "grit/generated_resources.h"
61 #include "grit/locale_settings.h" 66 #include "grit/locale_settings.h"
62 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h" 67 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h"
63 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h " 68 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h "
64 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" 69 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
65 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" 70 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
66 #include "ui/base/events/event_utils.h" 71 #include "ui/base/events/event_utils.h"
67 #include "ui/base/l10n/l10n_util.h" 72 #include "ui/base/l10n/l10n_util.h"
68 #include "ui/base/models/menu_model.h" 73 #include "ui/base/models/menu_model.h"
69 #include "ui/base/view_prop.h" 74 #include "ui/base/view_prop.h"
70 #include "ui/views/controls/webview/webview.h" 75 #include "ui/views/controls/webview/webview.h"
71 #include "ui/views/layout/grid_layout.h" 76 #include "ui/views/layout/grid_layout.h"
72 #include "ui/views/win/hwnd_message_handler.h" 77 #include "ui/views/widget/widget.h"
78
79 #if defined(USE_AURA)
80 #include "ui/aura/root_window.h"
81 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
82 #endif
73 83
74 using content::BrowserThread; 84 using content::BrowserThread;
75 using content::LoadNotificationDetails; 85 using content::LoadNotificationDetails;
76 using content::NativeWebKeyboardEvent; 86 using content::NativeWebKeyboardEvent;
77 using content::NavigationController; 87 using content::NavigationController;
78 using content::NavigationEntry; 88 using content::NavigationEntry;
79 using content::OpenURLParams; 89 using content::OpenURLParams;
80 using content::RenderViewHost; 90 using content::RenderViewHost;
81 using content::SSLStatus; 91 using content::SSLStatus;
82 using content::WebContents; 92 using content::WebContents;
83 using ui::ViewProp;
84 using WebKit::WebCString; 93 using WebKit::WebCString;
85 using WebKit::WebReferrerPolicy; 94 using WebKit::WebReferrerPolicy;
86 using WebKit::WebSecurityPolicy; 95 using WebKit::WebSecurityPolicy;
87 using WebKit::WebString; 96 using WebKit::WebString;
88 97
98 namespace {
99
89 static const char kWindowObjectKey[] = "ChromeWindowObject"; 100 static const char kWindowObjectKey[] = "ChromeWindowObject";
90 101
91 namespace { 102 // The following helper functions exist to localize UI toolkik-specific code.
103
104 HWND HWNDFromNativeView(gfx::NativeView native_view) {
105 #if defined(USE_AURA)
sky 2013/02/26 17:15:29 Use c/b/ui/views/hwnd_util.h
grt (UTC plus 2) 2013/02/27 16:53:11 Awesome! Done.
106 if (!native_view)
107 return NULL;
108 aura::RootWindow* root_window = native_view->GetRootWindow();
109 if (!root_window)
110 return NULL;
111 return root_window->GetAcceleratedWidget();
112 #else
113 return native_view;
114 #endif
115 }
116
117 void ShowNativeView(gfx::NativeView view) {
118 #if !defined(USE_AURA)
119 ::ShowWindow(view, SW_SHOWNA);
120 #endif
121 }
122
123 scoped_ptr<content::NativeWebKeyboardEvent> CreateKeyboardEvent(
124 const MSG& msg) {
125 #if defined(USE_AURA)
126 // TODO(grt): confirm that this is a translated character event.
127 ui::KeyEvent key_event(msg, true);
128 return scoped_ptr<content::NativeWebKeyboardEvent>(
129 new content::NativeWebKeyboardEvent(&key_event));
130 #else
131 return scoped_ptr<content::NativeWebKeyboardEvent>(
132 new content::NativeWebKeyboardEvent(msg));
133 #endif
134 }
135
136 const MSG& MessageFromKeyboardEvent(
137 const content::NativeWebKeyboardEvent& event) {
138 #if defined(USE_AURA)
139 return event.os_event->native_event();
140 #else
141 return event.os_event;
142 #endif
143 }
144
145 // A Widget class that notifies a WidgetLifecycleDelegate when it experiences
146 // lifecycle events.
147 class FilteringWidget : public views::Widget {
sky 2013/02/26 17:15:29 Move the methods you care about onto WidgetObserve
grt (UTC plus 2) 2013/02/27 16:53:11 Done. I haven't yet found any existing WidgetObser
148 public:
149 explicit FilteringWidget(WidgetLifecycleDelegate* delegate);
150 virtual ~FilteringWidget();
151
152 protected:
153 // views::internal::NativeWidgetDelegate methods.
154 virtual void OnNativeWidgetCreated() OVERRIDE;
155 virtual void OnNativeWidgetDestroying() OVERRIDE;
156 virtual void OnNativeWidgetDestroyed() OVERRIDE;
157
158 private:
159 WidgetLifecycleDelegate* delegate_;
160
161 DISALLOW_COPY_AND_ASSIGN(FilteringWidget);
162 };
163
164 FilteringWidget::FilteringWidget(
165 WidgetLifecycleDelegate* delegate)
166 : delegate_(delegate) {}
167
168 FilteringWidget::~FilteringWidget() {}
169
170 void FilteringWidget::OnNativeWidgetCreated() {
171 views::Widget::OnNativeWidgetCreated();
172 delegate_->OnNativeWidgetCreated();
173 }
174
175 void FilteringWidget::OnNativeWidgetDestroying() {
176 delegate_->OnNativeWidgetDestroying();
177 views::Widget::OnNativeWidgetDestroying();
178 }
179
180 void FilteringWidget::OnNativeWidgetDestroyed() {
181 views::Widget::OnNativeWidgetDestroyed();
182 delegate_->OnNativeWidgetDestroyed();
183 }
92 184
93 // Convert ui::MenuModel into a serializable form for Chrome Frame 185 // Convert ui::MenuModel into a serializable form for Chrome Frame
94 ContextMenuModel* ConvertMenuModel(const ui::MenuModel* ui_model) { 186 ContextMenuModel* ConvertMenuModel(const ui::MenuModel* ui_model) {
95 ContextMenuModel* new_model = new ContextMenuModel; 187 ContextMenuModel* new_model = new ContextMenuModel;
96 188
97 const int item_count = ui_model->GetItemCount(); 189 const int item_count = ui_model->GetItemCount();
98 new_model->items.reserve(item_count); 190 new_model->items.reserve(item_count);
99 for (int i = 0; i < item_count; ++i) { 191 for (int i = 0; i < item_count; ++i) {
100 if (ui_model->IsVisibleAt(i)) { 192 if (ui_model->IsVisibleAt(i)) {
101 ContextMenuModel::Item item; 193 ContextMenuModel::Item item;
(...skipping 13 matching lines...) Expand all
115 } 207 }
116 208
117 } // namespace 209 } // namespace
118 210
119 base::LazyInstance<ExternalTabContainerWin::PendingTabs> 211 base::LazyInstance<ExternalTabContainerWin::PendingTabs>
120 ExternalTabContainerWin::pending_tabs_ = LAZY_INSTANCE_INITIALIZER; 212 ExternalTabContainerWin::pending_tabs_ = LAZY_INSTANCE_INITIALIZER;
121 213
122 ExternalTabContainerWin::ExternalTabContainerWin( 214 ExternalTabContainerWin::ExternalTabContainerWin(
123 AutomationProvider* automation, 215 AutomationProvider* automation,
124 AutomationResourceMessageFilter* filter) 216 AutomationResourceMessageFilter* filter)
125 : views::NativeWidgetWin(new views::Widget), 217 : widget_(NULL),
126 automation_(automation), 218 automation_(automation),
127 tab_contents_container_(NULL), 219 tab_contents_container_(NULL),
128 tab_handle_(0), 220 tab_handle_(0),
129 ignore_next_load_notification_(false), 221 ignore_next_load_notification_(false),
130 automation_resource_message_filter_(filter), 222 automation_resource_message_filter_(filter),
131 load_requests_via_automation_(false), 223 load_requests_via_automation_(false),
132 handle_top_level_requests_(false), 224 handle_top_level_requests_(false),
133 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 225 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
134 pending_(false), 226 pending_(false),
135 focus_manager_(NULL), 227 focus_manager_(NULL),
(...skipping 23 matching lines...) Expand all
159 HWND parent, 251 HWND parent,
160 const gfx::Rect& bounds, 252 const gfx::Rect& bounds,
161 DWORD style, 253 DWORD style,
162 bool load_requests_via_automation, 254 bool load_requests_via_automation,
163 bool handle_top_level_requests, 255 bool handle_top_level_requests,
164 content::WebContents* existing_contents, 256 content::WebContents* existing_contents,
165 const GURL& initial_url, 257 const GURL& initial_url,
166 const GURL& referrer, 258 const GURL& referrer,
167 bool infobars_enabled, 259 bool infobars_enabled,
168 bool route_all_top_level_navigations) { 260 bool route_all_top_level_navigations) {
169 if (IsWindow(GetNativeView())) { 261 if (widget_) {
170 NOTREACHED(); 262 NOTREACHED();
171 return false; 263 return false;
172 } 264 }
173 265
266 widget_ = new FilteringWidget(this);
174 load_requests_via_automation_ = load_requests_via_automation; 267 load_requests_via_automation_ = load_requests_via_automation;
175 handle_top_level_requests_ = handle_top_level_requests; 268 handle_top_level_requests_ = handle_top_level_requests;
176 route_all_top_level_navigations_ = route_all_top_level_navigations; 269 route_all_top_level_navigations_ = route_all_top_level_navigations;
sky 2013/02/26 17:15:29 See this in the member initializer list too.
grt (UTC plus 2) 2013/02/27 16:53:11 Done.
177 270
178 GetMessageHandler()->set_window_style(WS_POPUP | WS_CLIPCHILDREN);
179
180 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 271 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
181 params.bounds = bounds; 272 params.bounds = bounds;
182 params.native_widget = this; 273 #if defined(USE_AURA)
183 GetWidget()->Init(params); 274 params.native_widget = new views::DesktopNativeWidgetAura(widget_);
184 if (!IsWindow(GetNativeView())) { 275 #endif
276 widget_->Init(params);
277 HWND window = HWNDFromNativeView(widget_->GetNativeView());
278
279 if (!IsWindow(window)) {
sky 2013/02/26 17:15:29 I believe Widget::Init CHECKs that an HWND is crea
grt (UTC plus 2) 2013/02/27 16:53:11 Looks like WindowImpl::Init has some CHECKs, so I
185 NOTREACHED(); 280 NOTREACHED();
186 return false; 281 return false;
187 } 282 }
188 283
189 // TODO(jcampan): limit focus traversal to contents. 284 // TODO(jcampan): limit focus traversal to contents.
190 285
191 prop_.reset(new ViewProp(GetNativeView(), kWindowObjectKey, this)); 286 prop_.reset(new ui::ViewProp(window, kWindowObjectKey, this));
192 287
193 if (existing_contents) { 288 if (existing_contents) {
194 existing_contents->GetController().SetBrowserContext(profile); 289 existing_contents->GetController().SetBrowserContext(profile);
195 } else { 290 } else {
196 existing_contents = WebContents::Create(WebContents::CreateParams(profile)); 291 existing_contents = WebContents::Create(WebContents::CreateParams(profile));
197 existing_contents->GetRenderViewHost()->AllowBindings( 292 existing_contents->GetRenderViewHost()->AllowBindings(
198 content::BINDINGS_POLICY_EXTERNAL_HOST); 293 content::BINDINGS_POLICY_EXTERNAL_HOST);
199 } 294 }
200 295
201 existing_contents->SetDelegate(this); 296 existing_contents->SetDelegate(this);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 weak_factory_.GetWeakPtr(), 330 weak_factory_.GetWeakPtr(),
236 initial_url, referrer)); 331 initial_url, referrer));
237 } 332 }
238 333
239 // We need WS_POPUP to be on the window during initialization, but 334 // We need WS_POPUP to be on the window during initialization, but
240 // once initialized we apply the requested style which may or may not 335 // once initialized we apply the requested style which may or may not
241 // include the popup bit. 336 // include the popup bit.
242 // Note that it's important to do this before we call SetParent since 337 // Note that it's important to do this before we call SetParent since
243 // during the SetParent call we will otherwise get a WA_ACTIVATE call 338 // during the SetParent call we will otherwise get a WA_ACTIVATE call
244 // that causes us to steal the current focus. 339 // that causes us to steal the current focus.
245 SetWindowLong( 340 SetWindowLong(window, GWL_STYLE,
246 GetNativeView(), GWL_STYLE, 341 (GetWindowLong(window, GWL_STYLE) & ~WS_POPUP) | style);
247 (GetWindowLong(GetNativeView(), GWL_STYLE) & ~WS_POPUP) | style);
248 342
249 // Now apply the parenting and style 343 // Now apply the parenting and style
250 if (parent) 344 if (parent)
251 SetParent(GetNativeView(), parent); 345 SetParent(window, parent);
252 346
253 ::ShowWindow(existing_contents->GetNativeView(), SW_SHOWNA); 347 ShowNativeView(existing_contents->GetNativeView());
254 348
255 LoadAccelerators(); 349 LoadAccelerators();
256 SetupExternalTabView(); 350 SetupExternalTabView();
257 BlockedContentTabHelper::FromWebContents(existing_contents)-> 351 BlockedContentTabHelper::FromWebContents(existing_contents)->
258 set_delegate(this); 352 set_delegate(this);
259 return true; 353 return true;
260 } 354 }
261 355
262 void ExternalTabContainerWin::Uninitialize() { 356 void ExternalTabContainerWin::Uninitialize() {
263 registrar_.RemoveAll(); 357 registrar_.RemoveAll();
264 if (web_contents_.get()) { 358 if (web_contents_.get()) {
359 tab_contents_container_->SetWebContents(NULL);
265 UnregisterRenderViewHost(web_contents_->GetRenderViewHost()); 360 UnregisterRenderViewHost(web_contents_->GetRenderViewHost());
266 361
267 // Explicitly tell the RPH to shutdown, as doing so is the only thing that 362 // Explicitly tell the RPH to shutdown, as doing so is the only thing that
268 // cleans up certain resources like infobars (crbug.com/148398). 363 // cleans up certain resources like infobars (crbug.com/148398).
269 // Tell the RPH to shutdown iff it has a page count of 1, meaning that 364 // Tell the RPH to shutdown iff it has a page count of 1, meaning that
270 // there is only a single remaining render widget host (the one owned by 365 // there is only a single remaining render widget host (the one owned by
271 // web_contents_) using this RPH. 366 // web_contents_) using this RPH.
272 // 367 //
273 // Note that it is not possible to simply call FastShutdownIfPossible on the 368 // Note that it is not possible to simply call FastShutdownIfPossible on the
274 // RPH here as that unfortunately ignores RPH's internal ref count, which 369 // RPH here as that unfortunately ignores RPH's internal ref count, which
275 // leaves any other render widget hosts using the same RPH dangling. 370 // leaves any other render widget hosts using the same RPH dangling.
276 // 371 //
277 // Note that in an ideal world, this would not be needed. The WebContents 372 // Note that in an ideal world, this would not be needed. The WebContents
278 // could just destroy itself, resulting in RPH::Release() eventually getting 373 // could just destroy itself, resulting in RPH::Release() eventually getting
279 // called and all would be neat and tidy. Sadly, the RPH only fires 374 // called and all would be neat and tidy. Sadly, the RPH only fires
280 // NOTIFICATION_RENDERER_PROCESS_CLOSED if one of the FastShutdownXXX 375 // NOTIFICATION_RENDERER_PROCESS_CLOSED if one of the FastShutdownXXX
281 // methods is called and other components rely on that notification to avoid 376 // methods is called and other components rely on that notification to avoid
282 // crashing on shutdown. Sad panda. Or maybe clinically depressed panda is 377 // crashing on shutdown. Sad panda. Or maybe clinically depressed panda is
283 // more fitting. 378 // more fitting.
284 web_contents_->GetRenderProcessHost()->FastShutdownForPageCount(1); 379 web_contents_->GetRenderProcessHost()->FastShutdownForPageCount(1);
285 380
286 if (GetWidget()->GetRootView()) 381 if (widget_->GetRootView())
287 GetWidget()->GetRootView()->RemoveAllChildViews(true); 382 widget_->GetRootView()->RemoveAllChildViews(true);
383 widget_ = NULL;
288 384
289 content::NotificationService::current()->Notify( 385 content::NotificationService::current()->Notify(
290 chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, 386 chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED,
291 content::Source<NavigationController>(&web_contents_->GetController()), 387 content::Source<NavigationController>(&web_contents_->GetController()),
292 content::Details<ExternalTabContainer>(this)); 388 content::Details<ExternalTabContainer>(this));
293 389
294 web_contents_.reset(NULL); 390 web_contents_.reset(NULL);
295 } 391 }
296 392
297 if (focus_manager_) { 393 if (focus_manager_) {
298 focus_manager_->UnregisterAccelerators(this); 394 focus_manager_->UnregisterAccelerators(this);
299 focus_manager_ = NULL; 395 focus_manager_ = NULL;
300 } 396 }
301 397
302 external_tab_view_ = NULL; 398 external_tab_view_ = NULL;
303 request_context_ = NULL; 399 request_context_ = NULL;
304 tab_contents_container_ = NULL; 400 tab_contents_container_ = NULL;
305 } 401 }
306 402
307 bool ExternalTabContainerWin::Reinitialize( 403 bool ExternalTabContainerWin::Reinitialize(
308 AutomationProvider* automation_provider, 404 AutomationProvider* automation_provider,
309 AutomationResourceMessageFilter* filter, 405 AutomationResourceMessageFilter* filter,
310 gfx::NativeWindow parent_window) { 406 HWND parent_window) {
311 if (!automation_provider || !filter) { 407 if (!automation_provider || !filter) {
312 NOTREACHED(); 408 NOTREACHED();
313 return false; 409 return false;
314 } 410 }
315 411
316 automation_ = automation_provider; 412 automation_ = automation_provider;
317 automation_resource_message_filter_ = filter; 413 automation_resource_message_filter_ = filter;
318 // Wait for the automation channel to be initialized before resuming pending 414 // Wait for the automation channel to be initialized before resuming pending
319 // render views and sending in the navigation state. 415 // render views and sending in the navigation state.
320 MessageLoop::current()->PostTask( 416 MessageLoop::current()->PostTask(
321 FROM_HERE, base::Bind(&ExternalTabContainerWin::OnReinitialize, 417 FROM_HERE, base::Bind(&ExternalTabContainerWin::OnReinitialize,
322 weak_factory_.GetWeakPtr())); 418 weak_factory_.GetWeakPtr()));
323 419
324 if (parent_window) 420 if (parent_window)
325 SetParent(GetNativeView(), parent_window); 421 SetParent(HWNDFromNativeView(widget_->GetNativeView()), parent_window);
326 return true; 422 return true;
327 } 423 }
328 424
329 WebContents* ExternalTabContainerWin::GetWebContents() const { 425 WebContents* ExternalTabContainerWin::GetWebContents() const {
330 return web_contents_.get(); 426 return web_contents_.get();
331 } 427 }
332 428
333 gfx::NativeView ExternalTabContainerWin::GetExternalTabNativeView() const { 429 HWND ExternalTabContainerWin::GetExternalTabHWND() const {
334 return GetNativeView(); 430 return HWNDFromNativeView(widget_->GetNativeView());
431 }
432
433 HWND ExternalTabContainerWin::GetContentHWND() const {
434 return HWNDFromNativeView(web_contents_->GetNativeView());
335 } 435 }
336 436
337 void ExternalTabContainerWin::SetTabHandle(int handle) { 437 void ExternalTabContainerWin::SetTabHandle(int handle) {
338 tab_handle_ = handle; 438 tab_handle_ = handle;
339 } 439 }
340 440
341 int ExternalTabContainerWin::GetTabHandle() const { 441 int ExternalTabContainerWin::GetTabHandle() const {
342 return tab_handle_; 442 return tab_handle_;
343 } 443 }
344 444
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 web_contents_.get() && 481 web_contents_.get() &&
382 Browser::RunUnloadEventsHelper(web_contents_.get()); 482 Browser::RunUnloadEventsHelper(web_contents_.get());
383 if (!wait_for_unload_handlers) { 483 if (!wait_for_unload_handlers) {
384 AutomationMsg_RunUnloadHandlers::WriteReplyParams(reply_message, true); 484 AutomationMsg_RunUnloadHandlers::WriteReplyParams(reply_message, true);
385 automation_->Send(reply_message); 485 automation_->Send(reply_message);
386 unload_reply_message_ = NULL; 486 unload_reply_message_ = NULL;
387 } 487 }
388 } 488 }
389 489
390 void ExternalTabContainerWin::ProcessUnhandledAccelerator(const MSG& msg) { 490 void ExternalTabContainerWin::ProcessUnhandledAccelerator(const MSG& msg) {
391 NativeWebKeyboardEvent keyboard_event(msg); 491 scoped_ptr<NativeWebKeyboardEvent> keyboard_event(CreateKeyboardEvent(msg));
392 unhandled_keyboard_event_handler_.HandleKeyboardEvent(keyboard_event, 492 unhandled_keyboard_event_handler_.HandleKeyboardEvent(*keyboard_event,
393 focus_manager_); 493 focus_manager_);
394 } 494 }
395 495
396 void ExternalTabContainerWin::FocusThroughTabTraversal( 496 void ExternalTabContainerWin::FocusThroughTabTraversal(
397 bool reverse, 497 bool reverse,
398 bool restore_focus_to_view) { 498 bool restore_focus_to_view) {
399 DCHECK(web_contents_.get()); 499 DCHECK(web_contents_.get());
400 if (web_contents_.get()) 500 if (web_contents_.get())
401 web_contents_->Focus(); 501 web_contents_->Focus();
402 502
403 // The web_contents_ member can get destroyed in the context of the call to 503 // The web_contents_ member can get destroyed in the context of the call to
404 // WebContentsViewViews::Focus() above. This method eventually calls SetFocus 504 // WebContentsViewViews::Focus() above. This method eventually calls SetFocus
405 // on the native window, which could end up dispatching messages like 505 // on the native window, which could end up dispatching messages like
406 // WM_DESTROY for the external tab. 506 // WM_DESTROY for the external tab.
407 if (web_contents_.get() && restore_focus_to_view) 507 if (web_contents_.get() && restore_focus_to_view)
408 web_contents_->FocusThroughTabTraversal(reverse); 508 web_contents_->FocusThroughTabTraversal(reverse);
409 } 509 }
410 510
411 // static
412 bool ExternalTabContainerWin::IsExternalTabContainer(HWND window) {
413 return ViewProp::GetValue(window, kWindowObjectKey) != NULL;
414 }
415
416 // static
417 ExternalTabContainer*
418 ExternalTabContainerWin::GetExternalContainerFromNativeWindow(
419 gfx::NativeView native_window) {
420 ExternalTabContainer* tab_container = NULL;
421 if (native_window) {
422 tab_container = reinterpret_cast<ExternalTabContainer*>(
423 ViewProp::GetValue(native_window, kWindowObjectKey));
424 }
425 return tab_container;
426 }
427 //////////////////////////////////////////////////////////////////////////////// 511 ////////////////////////////////////////////////////////////////////////////////
428 // ExternalTabContainer, content::WebContentsDelegate implementation: 512 // ExternalTabContainer, content::WebContentsDelegate implementation:
429 513
430 WebContents* ExternalTabContainerWin::OpenURLFromTab( 514 WebContents* ExternalTabContainerWin::OpenURLFromTab(
431 WebContents* source, 515 WebContents* source,
432 const OpenURLParams& params) { 516 const OpenURLParams& params) {
433 if (pending()) { 517 if (pending()) {
434 pending_open_url_requests_.push_back(params); 518 pending_open_url_requests_.push_back(params);
435 return NULL; 519 return NULL;
436 } 520 }
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 web_contents(), params)); 795 web_contents(), params));
712 static_cast<RenderViewContextMenuWin*>( 796 static_cast<RenderViewContextMenuWin*>(
713 external_context_menu_.get())->SetExternal(); 797 external_context_menu_.get())->SetExternal();
714 external_context_menu_->Init(); 798 external_context_menu_->Init();
715 external_context_menu_->UpdateMenuItemStates(); 799 external_context_menu_->UpdateMenuItemStates();
716 800
717 scoped_ptr<ContextMenuModel> context_menu_model( 801 scoped_ptr<ContextMenuModel> context_menu_model(
718 ConvertMenuModel(&external_context_menu_->menu_model())); 802 ConvertMenuModel(&external_context_menu_->menu_model()));
719 803
720 POINT screen_pt = { params.x, params.y }; 804 POINT screen_pt = { params.x, params.y };
721 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); 805 MapWindowPoints(HWNDFromNativeView(widget_->GetNativeView()), HWND_DESKTOP,
806 &screen_pt, 1);
722 807
723 MiniContextMenuParams ipc_params; 808 MiniContextMenuParams ipc_params;
724 ipc_params.screen_x = screen_pt.x; 809 ipc_params.screen_x = screen_pt.x;
725 ipc_params.screen_y = screen_pt.y; 810 ipc_params.screen_y = screen_pt.y;
726 ipc_params.link_url = params.link_url; 811 ipc_params.link_url = params.link_url;
727 ipc_params.unfiltered_link_url = params.unfiltered_link_url; 812 ipc_params.unfiltered_link_url = params.unfiltered_link_url;
728 ipc_params.src_url = params.src_url; 813 ipc_params.src_url = params.src_url;
729 ipc_params.page_url = params.page_url; 814 ipc_params.page_url = params.page_url;
730 ipc_params.keyword_url = params.keyword_url; 815 ipc_params.keyword_url = params.keyword_url;
731 ipc_params.frame_url = params.frame_url; 816 ipc_params.frame_url = params.frame_url;
(...skipping 10 matching lines...) Expand all
742 bool ExternalTabContainerWin::PreHandleKeyboardEvent( 827 bool ExternalTabContainerWin::PreHandleKeyboardEvent(
743 content::WebContents* source, 828 content::WebContents* source,
744 const NativeWebKeyboardEvent& event, 829 const NativeWebKeyboardEvent& event,
745 bool* is_keyboard_shortcut) { 830 bool* is_keyboard_shortcut) {
746 return false; 831 return false;
747 } 832 }
748 833
749 void ExternalTabContainerWin::HandleKeyboardEvent( 834 void ExternalTabContainerWin::HandleKeyboardEvent(
750 content::WebContents* source, 835 content::WebContents* source,
751 const NativeWebKeyboardEvent& event) { 836 const NativeWebKeyboardEvent& event) {
752 ProcessUnhandledKeyStroke(event.os_event.hwnd, event.os_event.message, 837 const MSG& message = MessageFromKeyboardEvent(event);
753 event.os_event.wParam, event.os_event.lParam); 838 ProcessUnhandledKeyStroke(message.hwnd, message.message,
839 message.wParam, message.lParam);
754 } 840 }
755 841
756 void ExternalTabContainerWin::BeforeUnloadFired(WebContents* tab, 842 void ExternalTabContainerWin::BeforeUnloadFired(WebContents* tab,
757 bool proceed, 843 bool proceed,
758 bool* proceed_to_fire_unload) { 844 bool* proceed_to_fire_unload) {
759 *proceed_to_fire_unload = true; 845 *proceed_to_fire_unload = true;
760 846
761 if (!automation_) { 847 if (!automation_) {
762 delete unload_reply_message_; 848 delete unload_reply_message_;
763 unload_reply_message_ = NULL; 849 unload_reply_message_ = NULL;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 RegisterRenderViewHostForAutomation(rvh, false); 1028 RegisterRenderViewHostForAutomation(rvh, false);
943 } 1029 }
944 break; 1030 break;
945 } 1031 }
946 default: 1032 default:
947 NOTREACHED(); 1033 NOTREACHED();
948 } 1034 }
949 } 1035 }
950 1036
951 //////////////////////////////////////////////////////////////////////////////// 1037 ////////////////////////////////////////////////////////////////////////////////
952 // ExternalTabContainer, views::NativeWidgetWin overrides: 1038 // WidgetLifecycleDelegate overrides:
953 1039
954 bool ExternalTabContainerWin::PreHandleMSG(UINT message, 1040 void ExternalTabContainerWin::OnNativeWidgetCreated() {
955 WPARAM w_param, 1041 // Grab a reference here which will be released in OnNativeWidgetDestroyed.
956 LPARAM l_param, 1042 AddRef();
957 LRESULT* result) {
958 if (message == WM_DESTROY) {
959 prop_.reset();
960 Uninitialize();
961 }
962 return false;
963 } 1043 }
964 1044
965 void ExternalTabContainerWin::PostHandleMSG(UINT message, 1045 void ExternalTabContainerWin::OnNativeWidgetDestroying() {
966 WPARAM w_param, 1046 Uninitialize();
967 LPARAM l_param) { 1047 prop_.reset();
968 // Grab a reference here which will be released in OnFinalMessage
969 if (message == WM_CREATE)
970 AddRef();
971 } 1048 }
972 1049
973 void ExternalTabContainerWin::OnFinalMessage(HWND window) { 1050 void ExternalTabContainerWin::OnNativeWidgetDestroyed() {
974 GetWidget()->OnNativeWidgetDestroyed(); 1051 // Release the reference which we grabbed in OnNativeWidgetCreated.
975 // Release the reference which we grabbed in WM_CREATE.
976 Release(); 1052 Release();
977 } 1053 }
978 1054
979 //////////////////////////////////////////////////////////////////////////////// 1055 ////////////////////////////////////////////////////////////////////////////////
980 // ExternalTabContainer, private: 1056 // ExternalTabContainer, private:
981 bool ExternalTabContainerWin::ProcessUnhandledKeyStroke(HWND window, 1057 bool ExternalTabContainerWin::ProcessUnhandledKeyStroke(HWND window,
982 UINT message, 1058 UINT message,
983 WPARAM wparam, 1059 WPARAM wparam,
984 LPARAM lparam) { 1060 LPARAM lparam) {
985 if (!automation_) { 1061 if (!automation_) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 // Nothing to do in that case. 1212 // Nothing to do in that case.
1137 return; 1213 return;
1138 } 1214 }
1139 1215
1140 scoped_array<ACCEL> scoped_accelerators(new ACCEL[count]); 1216 scoped_array<ACCEL> scoped_accelerators(new ACCEL[count]);
1141 ACCEL* accelerators = scoped_accelerators.get(); 1217 ACCEL* accelerators = scoped_accelerators.get();
1142 DCHECK(accelerators != NULL); 1218 DCHECK(accelerators != NULL);
1143 1219
1144 CopyAcceleratorTable(accelerator_table, accelerators, count); 1220 CopyAcceleratorTable(accelerator_table, accelerators, count);
1145 1221
1146 focus_manager_ = GetWidget()->GetFocusManager(); 1222 focus_manager_ = widget_->GetFocusManager();
1147 DCHECK(focus_manager_); 1223 DCHECK(focus_manager_);
1148 1224
1149 // Let's fill our own accelerator table. 1225 // Let's fill our own accelerator table.
1150 for (int i = 0; i < count; ++i) { 1226 for (int i = 0; i < count; ++i) {
1151 ui::Accelerator accelerator( 1227 ui::Accelerator accelerator(
1152 static_cast<ui::KeyboardCode>(accelerators[i].key), 1228 static_cast<ui::KeyboardCode>(accelerators[i].key),
1153 ui::GetModifiersFromACCEL(accelerators[i])); 1229 ui::GetModifiersFromACCEL(accelerators[i]));
1154 accelerator_table_[accelerator] = accelerators[i].cmd; 1230 accelerator_table_[accelerator] = accelerators[i].cmd;
1155 1231
1156 // Also register with the focus manager. 1232 // Also register with the focus manager.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 views::GridLayout::USE_PREF, 1290 views::GridLayout::USE_PREF,
1215 0, 1291 0,
1216 0); 1292 0);
1217 1293
1218 external_tab_view_->SetLayoutManager(layout); 1294 external_tab_view_->SetLayoutManager(layout);
1219 1295
1220 layout->StartRow(0, 0); 1296 layout->StartRow(0, 0);
1221 layout->AddView(info_bar_container); 1297 layout->AddView(info_bar_container);
1222 layout->StartRow(1, 0); 1298 layout->StartRow(1, 0);
1223 layout->AddView(tab_contents_container_); 1299 layout->AddView(tab_contents_container_);
1224 GetWidget()->SetContentsView(external_tab_view_); 1300 widget_->SetContentsView(external_tab_view_);
1225 // Note that SetWebContents must be called after AddChildView is called 1301 // Note that SetWebContents must be called after AddChildView is called
1226 tab_contents_container_->SetWebContents(web_contents()); 1302 tab_contents_container_->SetWebContents(web_contents());
1227 } 1303 }
1228 1304
1229 // static 1305 // static
1230 ExternalTabContainer* ExternalTabContainer::Create( 1306 ExternalTabContainer* ExternalTabContainer::Create(
1231 AutomationProvider* automation_provider, 1307 AutomationProvider* automation_provider,
1232 AutomationResourceMessageFilter* filter) { 1308 AutomationResourceMessageFilter* filter) {
1233 return new ExternalTabContainerWin(automation_provider, filter); 1309 return new ExternalTabContainerWin(automation_provider, filter);
1234 } 1310 }
1235 1311
1236 // static 1312 // static
1237 ExternalTabContainer* ExternalTabContainer::GetContainerForTab( 1313 ExternalTabContainer* ExternalTabContainer::GetContainerForTab(
1238 HWND tab_window) { 1314 content::WebContents* web_contents) {
1239 HWND parent_window = ::GetParent(tab_window); 1315 HWND parent_window =
1240 if (!::IsWindow(parent_window)) { 1316 HWNDFromNativeView(web_contents->GetView()->GetTopLevelNativeWindow());
1317 if (!::IsWindow(parent_window))
1241 return NULL; 1318 return NULL;
1242 } 1319 return reinterpret_cast<ExternalTabContainerWin*>(
1243 if (!ExternalTabContainerWin::IsExternalTabContainer(parent_window)) { 1320 ui::ViewProp::GetValue(parent_window, kWindowObjectKey));
1244 return NULL;
1245 }
1246 ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>(
1247 ViewProp::GetValue(parent_window, kWindowObjectKey));
1248 return container;
1249 } 1321 }
1250 1322
1251 // static 1323 // static
1252 scoped_refptr<ExternalTabContainer> ExternalTabContainer::RemovePendingTab( 1324 scoped_refptr<ExternalTabContainer> ExternalTabContainer::RemovePendingTab(
1253 uintptr_t cookie) { 1325 uintptr_t cookie) {
1254 return ExternalTabContainerWin::RemovePendingExternalTab(cookie); 1326 return ExternalTabContainerWin::RemovePendingExternalTab(cookie);
1255 } 1327 }
1256 1328
1257 /////////////////////////////////////////////////////////////////////////////// 1329 ///////////////////////////////////////////////////////////////////////////////
1258 // TemporaryPopupExternalTabContainerWin 1330 // TemporaryPopupExternalTabContainerWin
(...skipping 16 matching lines...) Expand all
1275 return NULL; 1347 return NULL;
1276 1348
1277 OpenURLParams forward_params = params; 1349 OpenURLParams forward_params = params;
1278 if (params.disposition == CURRENT_TAB) { 1350 if (params.disposition == CURRENT_TAB) {
1279 DCHECK(route_all_top_level_navigations_); 1351 DCHECK(route_all_top_level_navigations_);
1280 forward_params.disposition = NEW_FOREGROUND_TAB; 1352 forward_params.disposition = NEW_FOREGROUND_TAB;
1281 } 1353 }
1282 WebContents* new_contents = 1354 WebContents* new_contents =
1283 ExternalTabContainerWin::OpenURLFromTab(source, forward_params); 1355 ExternalTabContainerWin::OpenURLFromTab(source, forward_params);
1284 // support only one navigation for a dummy tab before it is killed. 1356 // support only one navigation for a dummy tab before it is killed.
1285 ::DestroyWindow(GetNativeView()); 1357 widget_->CloseNow();
1286 return new_contents; 1358 return new_contents;
1287 } 1359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698