OLD | NEW |
---|---|
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/extensions/shell_window.h" | 5 #include "chrome/browser/ui/extensions/shell_window.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/extension_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.h" |
9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" | 10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" |
11 #include "chrome/browser/extensions/shell_window_registry.h" | 11 #include "chrome/browser/extensions/shell_window_registry.h" |
12 #include "chrome/browser/extensions/tab_helper.h" | 12 #include "chrome/browser/extensions/tab_helper.h" |
13 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
13 #include "chrome/browser/file_select_helper.h" | 14 #include "chrome/browser/file_select_helper.h" |
14 #include "chrome/browser/infobars/infobar_tab_helper.h" | |
15 #include "chrome/browser/intents/web_intents_util.h" | 15 #include "chrome/browser/intents/web_intents_util.h" |
16 #include "chrome/browser/lifetime/application_lifetime.h" | 16 #include "chrome/browser/lifetime/application_lifetime.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_tabstrip.h" | 21 #include "chrome/browser/ui/browser_tabstrip.h" |
22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/browser/ui/constrained_window_tab_helper.h" | |
23 #include "chrome/browser/ui/extensions/native_shell_window.h" | 24 #include "chrome/browser/ui/extensions/native_shell_window.h" |
24 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | 25 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
26 #include "chrome/browser/view_type_utils.h" | 27 #include "chrome/browser/view_type_utils.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
29 #include "chrome/common/extensions/extension_messages.h" | 30 #include "chrome/common/extensions/extension_messages.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/invalidate_type.h" | 32 #include "content/public/browser/invalidate_type.h" |
32 #include "content/public/browser/navigation_entry.h" | 33 #include "content/public/browser/navigation_entry.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 const extensions::Extension* extension) | 92 const extensions::Extension* extension) |
92 : profile_(profile), | 93 : profile_(profile), |
93 extension_(extension), | 94 extension_(extension), |
94 web_contents_(NULL), | 95 web_contents_(NULL), |
95 ALLOW_THIS_IN_INITIALIZER_LIST( | 96 ALLOW_THIS_IN_INITIALIZER_LIST( |
96 extension_function_dispatcher_(profile, this)) { | 97 extension_function_dispatcher_(profile, this)) { |
97 } | 98 } |
98 | 99 |
99 void ShellWindow::Init(const GURL& url, | 100 void ShellWindow::Init(const GURL& url, |
100 const ShellWindow::CreateParams& params) { | 101 const ShellWindow::CreateParams& params) { |
101 web_contents_ = WebContents::Create( | 102 web_contents_.reset(WebContents::Create( |
102 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, | 103 profile(), SiteInstance::CreateForURL(profile(), url), MSG_ROUTING_NONE, |
103 NULL); | 104 NULL)); |
104 contents_.reset(TabContents::Factory::CreateTabContents(web_contents_)); | 105 ConstrainedWindowTabHelper::CreateForWebContents(web_contents_.get()); |
Ben Goodger (Google)
2012/10/22 16:09:50
qq for apps folk: why is ShellWindow using Constra
sail
2012/11/01 22:22:20
Hi Ben. I think of ConstrainedWindows as a way to
| |
105 content::WebContentsObserver::Observe(web_contents_); | 106 FaviconTabHelper::CreateForWebContents(web_contents_.get()); |
107 WebIntentPickerController::CreateForWebContents(web_contents_.get()); | |
Ben Goodger (Google)
2012/10/22 16:09:50
ditto all of this other stuff.
i'd like to see al
| |
108 | |
109 content::WebContentsObserver::Observe(web_contents_.get()); | |
106 web_contents_->SetDelegate(this); | 110 web_contents_->SetDelegate(this); |
107 chrome::SetViewType(web_contents_, chrome::VIEW_TYPE_APP_SHELL); | 111 chrome::SetViewType(web_contents_.get(), chrome::VIEW_TYPE_APP_SHELL); |
108 web_contents_->GetMutableRendererPrefs()-> | 112 web_contents_->GetMutableRendererPrefs()-> |
109 browser_handles_all_top_level_requests = true; | 113 browser_handles_all_top_level_requests = true; |
110 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | 114 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
111 | 115 |
112 native_window_.reset(NativeShellWindow::Create(this, params)); | 116 native_window_.reset(NativeShellWindow::Create(this, params)); |
113 | 117 |
114 if (!params.window_key.empty()) { | 118 if (!params.window_key.empty()) { |
115 window_key_ = params.window_key; | 119 window_key_ = params.window_key; |
116 | 120 |
117 if (params.restore_position || params.restore_size) { | 121 if (params.restore_position || params.restore_size) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 registrar_.RemoveAll(); | 167 registrar_.RemoveAll(); |
164 | 168 |
165 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 169 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
166 content::Source<Profile>(profile_)); | 170 content::Source<Profile>(profile_)); |
167 // Close when the browser is exiting. | 171 // Close when the browser is exiting. |
168 // TODO(mihaip): we probably don't want this in the long run (when platform | 172 // TODO(mihaip): we probably don't want this in the long run (when platform |
169 // apps are no longer tied to the browser process). | 173 // apps are no longer tied to the browser process). |
170 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 174 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
171 content::NotificationService::AllSources()); | 175 content::NotificationService::AllSources()); |
172 | 176 |
173 // Automatically dismiss all infobars. | |
174 InfoBarTabHelper* infobar_helper = | |
175 InfoBarTabHelper::FromWebContents(web_contents_); | |
176 infobar_helper->set_infobars_enabled(false); | |
177 | |
178 // Prevent the browser process from shutting down while this window is open. | 177 // Prevent the browser process from shutting down while this window is open. |
179 browser::StartKeepAlive(); | 178 browser::StartKeepAlive(); |
180 | 179 |
181 UpdateExtensionAppIcon(); | 180 UpdateExtensionAppIcon(); |
182 } | 181 } |
183 | 182 |
184 ShellWindow::~ShellWindow() { | 183 ShellWindow::~ShellWindow() { |
185 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the | 184 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the |
186 // last window open. | 185 // last window open. |
187 registrar_.RemoveAll(); | 186 registrar_.RemoveAll(); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 return true; | 361 return true; |
363 } | 362 } |
364 | 363 |
365 void ShellWindow::WebIntentDispatch( | 364 void ShellWindow::WebIntentDispatch( |
366 content::WebContents* web_contents, | 365 content::WebContents* web_contents, |
367 content::WebIntentsDispatcher* intents_dispatcher) { | 366 content::WebIntentsDispatcher* intents_dispatcher) { |
368 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) | 367 if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) |
369 return; | 368 return; |
370 | 369 |
371 WebIntentPickerController* web_intent_picker_controller = | 370 WebIntentPickerController* web_intent_picker_controller = |
372 WebIntentPickerController::FromWebContents(contents_->web_contents()); | 371 WebIntentPickerController::FromWebContents(web_contents_.get()); |
373 web_intent_picker_controller->SetIntentsDispatcher(intents_dispatcher); | 372 web_intent_picker_controller->SetIntentsDispatcher(intents_dispatcher); |
374 web_intent_picker_controller->ShowDialog( | 373 web_intent_picker_controller->ShowDialog( |
375 intents_dispatcher->GetIntent().action, | 374 intents_dispatcher->GetIntent().action, |
376 intents_dispatcher->GetIntent().type); | 375 intents_dispatcher->GetIntent().type); |
377 } | 376 } |
378 | 377 |
379 void ShellWindow::RunFileChooser(WebContents* tab, | 378 void ShellWindow::RunFileChooser(WebContents* tab, |
380 const content::FileChooserParams& params) { | 379 const content::FileChooserParams& params) { |
381 FileSelectHelper::RunFileChooser(tab, params); | 380 FileSelectHelper::RunFileChooser(tab, params); |
382 } | 381 } |
383 | 382 |
384 bool ShellWindow::IsPopupOrPanel(const WebContents* source) const { | 383 bool ShellWindow::IsPopupOrPanel(const WebContents* source) const { |
385 DCHECK(source == web_contents_); | 384 DCHECK(source == web_contents_.get()); |
386 return true; | 385 return true; |
387 } | 386 } |
388 | 387 |
389 void ShellWindow::MoveContents(WebContents* source, const gfx::Rect& pos) { | 388 void ShellWindow::MoveContents(WebContents* source, const gfx::Rect& pos) { |
390 DCHECK(source == web_contents_); | 389 DCHECK(source == web_contents_.get()); |
391 native_window_->SetBounds(pos); | 390 native_window_->SetBounds(pos); |
392 } | 391 } |
393 | 392 |
394 void ShellWindow::NavigationStateChanged( | 393 void ShellWindow::NavigationStateChanged( |
395 const content::WebContents* source, unsigned changed_flags) { | 394 const content::WebContents* source, unsigned changed_flags) { |
396 DCHECK(source == web_contents_); | 395 DCHECK(source == web_contents_.get()); |
397 if (changed_flags & content::INVALIDATE_TYPE_TITLE) | 396 if (changed_flags & content::INVALIDATE_TYPE_TITLE) |
398 native_window_->UpdateWindowTitle(); | 397 native_window_->UpdateWindowTitle(); |
399 else if (changed_flags & content::INVALIDATE_TYPE_TAB) | 398 else if (changed_flags & content::INVALIDATE_TYPE_TAB) |
400 native_window_->UpdateWindowIcon(); | 399 native_window_->UpdateWindowIcon(); |
401 } | 400 } |
402 | 401 |
403 void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, | 402 void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, |
404 bool enter_fullscreen) { | 403 bool enter_fullscreen) { |
405 DCHECK(source == web_contents_); | 404 DCHECK(source == web_contents_.get()); |
406 native_window_->SetFullscreen(enter_fullscreen); | 405 native_window_->SetFullscreen(enter_fullscreen); |
407 } | 406 } |
408 | 407 |
409 bool ShellWindow::IsFullscreenForTabOrPending( | 408 bool ShellWindow::IsFullscreenForTabOrPending( |
410 const content::WebContents* source) const { | 409 const content::WebContents* source) const { |
411 DCHECK(source == web_contents_); | 410 DCHECK(source == web_contents_.get()); |
412 return native_window_->IsFullscreenOrPending(); | 411 return native_window_->IsFullscreenOrPending(); |
413 } | 412 } |
414 | 413 |
415 void ShellWindow::Observe(int type, | 414 void ShellWindow::Observe(int type, |
416 const content::NotificationSource& source, | 415 const content::NotificationSource& source, |
417 const content::NotificationDetails& details) { | 416 const content::NotificationDetails& details) { |
418 switch (type) { | 417 switch (type) { |
419 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { | 418 case content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED: { |
420 // TODO(jeremya): once http://crbug.com/123007 is fixed, we'll no longer | 419 // TODO(jeremya): once http://crbug.com/123007 is fixed, we'll no longer |
421 // need to suspend resource requests here (the call in the constructor | 420 // need to suspend resource requests here (the call in the constructor |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 const extensions::DraggableRegion& region = *iter; | 487 const extensions::DraggableRegion& region = *iter; |
489 sk_region->op( | 488 sk_region->op( |
490 region.bounds.x(), | 489 region.bounds.x(), |
491 region.bounds.y(), | 490 region.bounds.y(), |
492 region.bounds.right(), | 491 region.bounds.right(), |
493 region.bounds.bottom(), | 492 region.bounds.bottom(), |
494 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 493 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
495 } | 494 } |
496 return sk_region; | 495 return sk_region; |
497 } | 496 } |
OLD | NEW |