OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/shell_window.h" | 5 #include "apps/shell_window.h" |
6 | 6 |
7 #include "apps/shell_window_geometry_cache.h" | 7 #include "apps/shell_window_geometry_cache.h" |
8 #include "apps/shell_window_registry.h" | 8 #include "apps/shell_window_registry.h" |
9 #include "apps/ui/native_app_window.h" | 9 #include "apps/ui/native_app_window.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/extensions/extension_web_contents_observer.h" | 15 #include "chrome/browser/extensions/extension_web_contents_observer.h" |
16 #include "chrome/browser/extensions/suggest_permission_util.h" | 16 #include "chrome/browser/extensions/suggest_permission_util.h" |
17 #include "chrome/browser/lifetime/application_lifetime.h" | 17 #include "chrome/browser/lifetime/application_lifetime.h" |
18 #include "chrome/browser/profiles/profile.h" | |
19 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/extensions/extension_messages.h" | 19 #include "chrome/common/extensions/extension_messages.h" |
21 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 20 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
22 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 21 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 22 #include "content/public/browser/browser_context.h" |
23 #include "content/public/browser/invalidate_type.h" | 23 #include "content/public/browser/invalidate_type.h" |
24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/resource_dispatcher_host.h" | 30 #include "content/public/browser/resource_dispatcher_host.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "content/public/browser/web_contents_view.h" | 32 #include "content/public/browser/web_contents_view.h" |
33 #include "content/public/common/media_stream_request.h" | 33 #include "content/public/common/media_stream_request.h" |
34 #include "extensions/browser/extension_system.h" | 34 #include "extensions/browser/extension_system.h" |
| 35 #include "extensions/browser/extensions_browser_client.h" |
35 #include "extensions/browser/process_manager.h" | 36 #include "extensions/browser/process_manager.h" |
36 #include "extensions/browser/view_type_utils.h" | 37 #include "extensions/browser/view_type_utils.h" |
37 #include "extensions/common/extension.h" | 38 #include "extensions/common/extension.h" |
38 #include "third_party/skia/include/core/SkRegion.h" | 39 #include "third_party/skia/include/core/SkRegion.h" |
39 #include "ui/gfx/screen.h" | 40 #include "ui/gfx/screen.h" |
40 | 41 |
41 #if !defined(OS_MACOSX) | 42 #if !defined(OS_MACOSX) |
42 #include "apps/pref_names.h" | 43 #include "apps/pref_names.h" |
43 #include "base/prefs/pref_service.h" | 44 #include "base/prefs/pref_service.h" |
44 #endif | 45 #endif |
45 | 46 |
| 47 using content::BrowserContext; |
46 using content::ConsoleMessageLevel; | 48 using content::ConsoleMessageLevel; |
47 using content::WebContents; | 49 using content::WebContents; |
48 using extensions::APIPermission; | 50 using extensions::APIPermission; |
49 using web_modal::WebContentsModalDialogHost; | 51 using web_modal::WebContentsModalDialogHost; |
50 using web_modal::WebContentsModalDialogManager; | 52 using web_modal::WebContentsModalDialogManager; |
51 | 53 |
52 namespace { | 54 namespace { |
53 | 55 |
54 const int kDefaultWidth = 512; | 56 const int kDefaultWidth = 512; |
55 const int kDefaultHeight = 384; | 57 const int kDefaultHeight = 384; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 state(ui::SHOW_STATE_DEFAULT), | 132 state(ui::SHOW_STATE_DEFAULT), |
131 hidden(false), | 133 hidden(false), |
132 resizable(true), | 134 resizable(true), |
133 focused(true), | 135 focused(true), |
134 always_on_top(false) {} | 136 always_on_top(false) {} |
135 | 137 |
136 ShellWindow::CreateParams::~CreateParams() {} | 138 ShellWindow::CreateParams::~CreateParams() {} |
137 | 139 |
138 ShellWindow::Delegate::~Delegate() {} | 140 ShellWindow::Delegate::~Delegate() {} |
139 | 141 |
140 ShellWindow::ShellWindow(Profile* profile, | 142 ShellWindow::ShellWindow(BrowserContext* context, |
141 Delegate* delegate, | 143 Delegate* delegate, |
142 const extensions::Extension* extension) | 144 const extensions::Extension* extension) |
143 : profile_(profile), | 145 : browser_context_(context), |
144 extension_(extension), | 146 extension_(extension), |
145 extension_id_(extension->id()), | 147 extension_id_(extension->id()), |
146 window_type_(WINDOW_TYPE_DEFAULT), | 148 window_type_(WINDOW_TYPE_DEFAULT), |
147 delegate_(delegate), | 149 delegate_(delegate), |
148 image_loader_ptr_factory_(this), | 150 image_loader_ptr_factory_(this), |
149 fullscreen_types_(FULLSCREEN_TYPE_NONE), | 151 fullscreen_types_(FULLSCREEN_TYPE_NONE), |
150 show_on_first_paint_(false), | 152 show_on_first_paint_(false), |
151 first_paint_complete_(false), | 153 first_paint_complete_(false), |
152 cached_always_on_top_(false) { | 154 cached_always_on_top_(false) { |
153 CHECK(!profile->IsGuestSession() || profile->IsOffTheRecord()) | 155 extensions::ExtensionsBrowserClient* client = |
| 156 extensions::ExtensionsBrowserClient::Get(); |
| 157 CHECK(!client->IsGuestSession(context) || context->IsOffTheRecord()) |
154 << "Only off the record window may be opened in the guest mode."; | 158 << "Only off the record window may be opened in the guest mode."; |
155 } | 159 } |
156 | 160 |
157 void ShellWindow::Init(const GURL& url, | 161 void ShellWindow::Init(const GURL& url, |
158 ShellWindowContents* shell_window_contents, | 162 ShellWindowContents* shell_window_contents, |
159 const CreateParams& params) { | 163 const CreateParams& params) { |
160 // Initialize the render interface and web contents | 164 // Initialize the render interface and web contents |
161 shell_window_contents_.reset(shell_window_contents); | 165 shell_window_contents_.reset(shell_window_contents); |
162 shell_window_contents_->Initialize(profile(), url); | 166 shell_window_contents_->Initialize(browser_context(), url); |
163 WebContents* web_contents = shell_window_contents_->GetWebContents(); | 167 WebContents* web_contents = shell_window_contents_->GetWebContents(); |
164 if (CommandLine::ForCurrentProcess()->HasSwitch( | 168 if (CommandLine::ForCurrentProcess()->HasSwitch( |
165 switches::kEnableAppsShowOnFirstPaint)) { | 169 switches::kEnableAppsShowOnFirstPaint)) { |
166 content::WebContentsObserver::Observe(web_contents); | 170 content::WebContentsObserver::Observe(web_contents); |
167 } | 171 } |
168 delegate_->InitWebContents(web_contents); | 172 delegate_->InitWebContents(web_contents); |
169 WebContentsModalDialogManager::CreateForWebContents(web_contents); | 173 WebContentsModalDialogManager::CreateForWebContents(web_contents); |
170 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents); | 174 extensions::ExtensionWebContentsObserver::CreateForWebContents(web_contents); |
171 | 175 |
172 web_contents->SetDelegate(this); | 176 web_contents->SetDelegate(this); |
(...skipping 27 matching lines...) Expand all Loading... |
200 Maximize(); | 204 Maximize(); |
201 else if (new_params.state == ui::SHOW_STATE_MINIMIZED) | 205 else if (new_params.state == ui::SHOW_STATE_MINIMIZED) |
202 Minimize(); | 206 Minimize(); |
203 | 207 |
204 OnNativeWindowChanged(); | 208 OnNativeWindowChanged(); |
205 | 209 |
206 // When the render view host is changed, the native window needs to know | 210 // When the render view host is changed, the native window needs to know |
207 // about it in case it has any setup to do to make the renderer appear | 211 // about it in case it has any setup to do to make the renderer appear |
208 // properly. In particular, on Windows, the view's clickthrough region needs | 212 // properly. In particular, on Windows, the view's clickthrough region needs |
209 // to be set. | 213 // to be set. |
210 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 214 extensions::ExtensionsBrowserClient* client = |
211 content::Source<Profile>(profile_->GetOriginalProfile())); | 215 extensions::ExtensionsBrowserClient::Get(); |
| 216 registrar_.Add(this, |
| 217 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 218 content::Source<content::BrowserContext>( |
| 219 client->GetOriginalContext(browser_context_))); |
212 // Close when the browser process is exiting. | 220 // Close when the browser process is exiting. |
213 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 221 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
214 content::NotificationService::AllSources()); | 222 content::NotificationService::AllSources()); |
215 | 223 |
216 shell_window_contents_->LoadContents(new_params.creator_process_id); | 224 shell_window_contents_->LoadContents(new_params.creator_process_id); |
217 | 225 |
218 if (CommandLine::ForCurrentProcess()->HasSwitch( | 226 if (CommandLine::ForCurrentProcess()->HasSwitch( |
219 switches::kEnableAppsShowOnFirstPaint)) { | 227 switches::kEnableAppsShowOnFirstPaint)) { |
220 // We want to show the window only when the content has been painted. For | 228 // We want to show the window only when the content has been painted. For |
221 // that to happen, we need to define a size for the content, otherwise the | 229 // that to happen, we need to define a size for the content, otherwise the |
222 // layout will happen in a 0x0 area. | 230 // layout will happen in a 0x0 area. |
223 // Note: WebContents::GetView() is guaranteed to be non-null. | 231 // Note: WebContents::GetView() is guaranteed to be non-null. |
224 web_contents->GetView()->SizeContents(new_params.bounds.size()); | 232 web_contents->GetView()->SizeContents(new_params.bounds.size()); |
225 } | 233 } |
226 | 234 |
227 // Prevent the browser process from shutting down while this window is open. | 235 // Prevent the browser process from shutting down while this window is open. |
228 chrome::StartKeepAlive(); | 236 chrome::StartKeepAlive(); |
229 | 237 |
230 UpdateExtensionAppIcon(); | 238 UpdateExtensionAppIcon(); |
231 | 239 |
232 ShellWindowRegistry::Get(profile_)->AddShellWindow(this); | 240 ShellWindowRegistry::Get(browser_context_)->AddShellWindow(this); |
233 } | 241 } |
234 | 242 |
235 ShellWindow::~ShellWindow() { | 243 ShellWindow::~ShellWindow() { |
236 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the | 244 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the |
237 // last window open. | 245 // last window open. |
238 registrar_.RemoveAll(); | 246 registrar_.RemoveAll(); |
239 | 247 |
240 // Remove shutdown prevention. | 248 // Remove shutdown prevention. |
241 chrome::EndKeepAlive(); | 249 chrome::EndKeepAlive(); |
242 } | 250 } |
(...skipping 22 matching lines...) Expand all Loading... |
265 params.url.spec().c_str())); | 273 params.url.spec().c_str())); |
266 return NULL; | 274 return NULL; |
267 } | 275 } |
268 | 276 |
269 // These dispositions aren't really navigations. | 277 // These dispositions aren't really navigations. |
270 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || | 278 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || |
271 disposition == IGNORE_ACTION) { | 279 disposition == IGNORE_ACTION) { |
272 return NULL; | 280 return NULL; |
273 } | 281 } |
274 | 282 |
275 WebContents* contents = delegate_->OpenURLFromTab(profile_, source, | 283 WebContents* contents = |
276 params); | 284 delegate_->OpenURLFromTab(browser_context_, source, params); |
277 if (!contents) { | 285 if (!contents) { |
278 AddMessageToDevToolsConsole( | 286 AddMessageToDevToolsConsole( |
279 content::CONSOLE_MESSAGE_LEVEL_ERROR, | 287 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
280 base::StringPrintf( | 288 base::StringPrintf( |
281 "Can't navigate to \"%s\"; apps do not support navigation.", | 289 "Can't navigate to \"%s\"; apps do not support navigation.", |
282 params.url.spec().c_str())); | 290 params.url.spec().c_str())); |
283 } | 291 } |
284 | 292 |
285 return contents; | 293 return contents; |
286 } | 294 } |
287 | 295 |
288 void ShellWindow::AddNewContents(WebContents* source, | 296 void ShellWindow::AddNewContents(WebContents* source, |
289 WebContents* new_contents, | 297 WebContents* new_contents, |
290 WindowOpenDisposition disposition, | 298 WindowOpenDisposition disposition, |
291 const gfx::Rect& initial_pos, | 299 const gfx::Rect& initial_pos, |
292 bool user_gesture, | 300 bool user_gesture, |
293 bool* was_blocked) { | 301 bool* was_blocked) { |
294 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == | 302 DCHECK(new_contents->GetBrowserContext() == browser_context_); |
295 profile_); | 303 delegate_->AddNewContents(browser_context_, |
296 delegate_->AddNewContents(profile_, new_contents, disposition, | 304 new_contents, |
297 initial_pos, user_gesture, was_blocked); | 305 disposition, |
| 306 initial_pos, |
| 307 user_gesture, |
| 308 was_blocked); |
298 } | 309 } |
299 | 310 |
300 bool ShellWindow::PreHandleKeyboardEvent( | 311 bool ShellWindow::PreHandleKeyboardEvent( |
301 content::WebContents* source, | 312 content::WebContents* source, |
302 const content::NativeWebKeyboardEvent& event, | 313 const content::NativeWebKeyboardEvent& event, |
303 bool* is_keyboard_shortcut) { | 314 bool* is_keyboard_shortcut) { |
304 // Here, we can handle a key event before the content gets it. When we are | 315 // Here, we can handle a key event before the content gets it. When we are |
305 // fullscreen and it is not forced, we want to allow the user to leave | 316 // fullscreen and it is not forced, we want to allow the user to leave |
306 // when ESC is pressed. | 317 // when ESC is pressed. |
307 // However, if the application has the "overrideEscFullscreen" permission, we | 318 // However, if the application has the "overrideEscFullscreen" permission, we |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 void ShellWindow::DidFirstVisuallyNonEmptyPaint(int32 page_id) { | 370 void ShellWindow::DidFirstVisuallyNonEmptyPaint(int32 page_id) { |
360 first_paint_complete_ = true; | 371 first_paint_complete_ = true; |
361 if (show_on_first_paint_) { | 372 if (show_on_first_paint_) { |
362 DCHECK(delayed_show_type_ == SHOW_ACTIVE || | 373 DCHECK(delayed_show_type_ == SHOW_ACTIVE || |
363 delayed_show_type_ == SHOW_INACTIVE); | 374 delayed_show_type_ == SHOW_INACTIVE); |
364 Show(delayed_show_type_); | 375 Show(delayed_show_type_); |
365 } | 376 } |
366 } | 377 } |
367 | 378 |
368 void ShellWindow::OnNativeClose() { | 379 void ShellWindow::OnNativeClose() { |
369 ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this); | 380 ShellWindowRegistry::Get(browser_context_)->RemoveShellWindow(this); |
370 if (shell_window_contents_) { | 381 if (shell_window_contents_) { |
371 WebContents* web_contents = shell_window_contents_->GetWebContents(); | 382 WebContents* web_contents = shell_window_contents_->GetWebContents(); |
372 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 383 WebContentsModalDialogManager::FromWebContents(web_contents)-> |
373 SetDelegate(NULL); | 384 SetDelegate(NULL); |
374 shell_window_contents_->NativeWindowClosed(); | 385 shell_window_contents_->NativeWindowClosed(); |
375 } | 386 } |
376 delete this; | 387 delete this; |
377 } | 388 } |
378 | 389 |
379 void ShellWindow::OnNativeWindowChanged() { | 390 void ShellWindow::OnNativeWindowChanged() { |
380 SaveWindowPosition(); | 391 SaveWindowPosition(); |
381 | 392 |
382 #if defined(OS_WIN) | 393 #if defined(OS_WIN) |
383 if (native_app_window_ && | 394 if (native_app_window_ && |
384 cached_always_on_top_ && | 395 cached_always_on_top_ && |
385 !IsFullscreen(fullscreen_types_) && | 396 !IsFullscreen(fullscreen_types_) && |
386 !native_app_window_->IsMaximized() && | 397 !native_app_window_->IsMaximized() && |
387 !native_app_window_->IsMinimized()) { | 398 !native_app_window_->IsMinimized()) { |
388 UpdateNativeAlwaysOnTop(); | 399 UpdateNativeAlwaysOnTop(); |
389 } | 400 } |
390 #endif | 401 #endif |
391 | 402 |
392 if (shell_window_contents_ && native_app_window_) | 403 if (shell_window_contents_ && native_app_window_) |
393 shell_window_contents_->NativeWindowChanged(native_app_window_.get()); | 404 shell_window_contents_->NativeWindowChanged(native_app_window_.get()); |
394 } | 405 } |
395 | 406 |
396 void ShellWindow::OnNativeWindowActivated() { | 407 void ShellWindow::OnNativeWindowActivated() { |
397 ShellWindowRegistry::Get(profile_)->ShellWindowActivated(this); | 408 ShellWindowRegistry::Get(browser_context_)->ShellWindowActivated(this); |
398 } | 409 } |
399 | 410 |
400 content::WebContents* ShellWindow::web_contents() const { | 411 content::WebContents* ShellWindow::web_contents() const { |
401 return shell_window_contents_->GetWebContents(); | 412 return shell_window_contents_->GetWebContents(); |
402 } | 413 } |
403 | 414 |
404 NativeAppWindow* ShellWindow::GetBaseWindow() { | 415 NativeAppWindow* ShellWindow::GetBaseWindow() { |
405 return native_app_window_.get(); | 416 return native_app_window_.get(); |
406 } | 417 } |
407 | 418 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 void ShellWindow::UpdateDraggableRegions( | 492 void ShellWindow::UpdateDraggableRegions( |
482 const std::vector<extensions::DraggableRegion>& regions) { | 493 const std::vector<extensions::DraggableRegion>& regions) { |
483 native_app_window_->UpdateDraggableRegions(regions); | 494 native_app_window_->UpdateDraggableRegions(regions); |
484 } | 495 } |
485 | 496 |
486 void ShellWindow::UpdateAppIcon(const gfx::Image& image) { | 497 void ShellWindow::UpdateAppIcon(const gfx::Image& image) { |
487 if (image.IsEmpty()) | 498 if (image.IsEmpty()) |
488 return; | 499 return; |
489 app_icon_ = image; | 500 app_icon_ = image; |
490 native_app_window_->UpdateWindowIcon(); | 501 native_app_window_->UpdateWindowIcon(); |
491 ShellWindowRegistry::Get(profile_)->ShellWindowIconChanged(this); | 502 ShellWindowRegistry::Get(browser_context_)->ShellWindowIconChanged(this); |
492 } | 503 } |
493 | 504 |
494 void ShellWindow::Fullscreen() { | 505 void ShellWindow::Fullscreen() { |
495 #if !defined(OS_MACOSX) | 506 #if !defined(OS_MACOSX) |
496 // Do not enter fullscreen mode if disallowed by pref. | 507 // Do not enter fullscreen mode if disallowed by pref. |
497 if (!profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) | 508 PrefService* prefs = |
| 509 extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( |
| 510 browser_context()); |
| 511 if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed)) |
498 return; | 512 return; |
499 #endif | 513 #endif |
500 fullscreen_types_ |= FULLSCREEN_TYPE_WINDOW_API; | 514 fullscreen_types_ |= FULLSCREEN_TYPE_WINDOW_API; |
501 SetNativeWindowFullscreen(); | 515 SetNativeWindowFullscreen(); |
502 } | 516 } |
503 | 517 |
504 void ShellWindow::Maximize() { | 518 void ShellWindow::Maximize() { |
505 GetBaseWindow()->Maximize(); | 519 GetBaseWindow()->Maximize(); |
506 } | 520 } |
507 | 521 |
508 void ShellWindow::Minimize() { | 522 void ShellWindow::Minimize() { |
509 GetBaseWindow()->Minimize(); | 523 GetBaseWindow()->Minimize(); |
510 } | 524 } |
511 | 525 |
512 void ShellWindow::Restore() { | 526 void ShellWindow::Restore() { |
513 if (IsFullscreen(fullscreen_types_)) { | 527 if (IsFullscreen(fullscreen_types_)) { |
514 fullscreen_types_ = FULLSCREEN_TYPE_NONE; | 528 fullscreen_types_ = FULLSCREEN_TYPE_NONE; |
515 SetNativeWindowFullscreen(); | 529 SetNativeWindowFullscreen(); |
516 } else { | 530 } else { |
517 GetBaseWindow()->Restore(); | 531 GetBaseWindow()->Restore(); |
518 } | 532 } |
519 } | 533 } |
520 | 534 |
521 void ShellWindow::OSFullscreen() { | 535 void ShellWindow::OSFullscreen() { |
522 #if !defined(OS_MACOSX) | 536 #if !defined(OS_MACOSX) |
523 // Do not enter fullscreen mode if disallowed by pref. | 537 // Do not enter fullscreen mode if disallowed by pref. |
524 if (!profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) | 538 PrefService* prefs = |
| 539 extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( |
| 540 browser_context()); |
| 541 if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed)) |
525 return; | 542 return; |
526 #endif | 543 #endif |
527 fullscreen_types_ |= FULLSCREEN_TYPE_OS; | 544 fullscreen_types_ |= FULLSCREEN_TYPE_OS; |
528 SetNativeWindowFullscreen(); | 545 SetNativeWindowFullscreen(); |
529 } | 546 } |
530 | 547 |
531 void ShellWindow::ForcedFullscreen() { | 548 void ShellWindow::ForcedFullscreen() { |
532 fullscreen_types_ |= FULLSCREEN_TYPE_FORCED; | 549 fullscreen_types_ |= FULLSCREEN_TYPE_FORCED; |
533 SetNativeWindowFullscreen(); | 550 SetNativeWindowFullscreen(); |
534 } | 551 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 void ShellWindow::OnExtensionIconImageChanged(extensions::IconImage* image) { | 677 void ShellWindow::OnExtensionIconImageChanged(extensions::IconImage* image) { |
661 DCHECK_EQ(app_icon_image_.get(), image); | 678 DCHECK_EQ(app_icon_image_.get(), image); |
662 | 679 |
663 UpdateAppIcon(gfx::Image(app_icon_image_->image_skia())); | 680 UpdateAppIcon(gfx::Image(app_icon_image_->image_skia())); |
664 } | 681 } |
665 | 682 |
666 void ShellWindow::UpdateExtensionAppIcon() { | 683 void ShellWindow::UpdateExtensionAppIcon() { |
667 // Avoid using any previous app icons were being downloaded. | 684 // Avoid using any previous app icons were being downloaded. |
668 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 685 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
669 | 686 |
670 app_icon_image_.reset(new extensions::IconImage( | 687 app_icon_image_.reset( |
671 profile(), | 688 new extensions::IconImage(browser_context(), |
672 extension(), | 689 extension(), |
673 extensions::IconsInfo::GetIcons(extension()), | 690 extensions::IconsInfo::GetIcons(extension()), |
674 delegate_->PreferredIconSize(), | 691 delegate_->PreferredIconSize(), |
675 extensions::IconsInfo::GetDefaultAppIcon(), | 692 extensions::IconsInfo::GetDefaultAppIcon(), |
676 this)); | 693 this)); |
677 | 694 |
678 // Triggers actual image loading with 1x resources. The 2x resource will | 695 // Triggers actual image loading with 1x resources. The 2x resource will |
679 // be handled by IconImage class when requested. | 696 // be handled by IconImage class when requested. |
680 app_icon_image_->image_skia().GetRepresentation(1.0f); | 697 app_icon_image_->image_skia().GetRepresentation(1.0f); |
681 } | 698 } |
682 | 699 |
683 void ShellWindow::OnSizeConstraintsChanged() { | 700 void ShellWindow::OnSizeConstraintsChanged() { |
684 native_app_window_->UpdateWindowMinMaxSize(); | 701 native_app_window_->UpdateWindowMinMaxSize(); |
685 gfx::Rect bounds = GetClientBounds(); | 702 gfx::Rect bounds = GetClientBounds(); |
686 gfx::Size constrained_size = size_constraints_.ClampSize(bounds.size()); | 703 gfx::Size constrained_size = size_constraints_.ClampSize(bounds.size()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 else if (changed_flags & content::INVALIDATE_TYPE_TAB) | 796 else if (changed_flags & content::INVALIDATE_TYPE_TAB) |
780 native_app_window_->UpdateWindowIcon(); | 797 native_app_window_->UpdateWindowIcon(); |
781 } | 798 } |
782 | 799 |
783 void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, | 800 void ShellWindow::ToggleFullscreenModeForTab(content::WebContents* source, |
784 bool enter_fullscreen) { | 801 bool enter_fullscreen) { |
785 #if !defined(OS_MACOSX) | 802 #if !defined(OS_MACOSX) |
786 // Do not enter fullscreen mode if disallowed by pref. | 803 // Do not enter fullscreen mode if disallowed by pref. |
787 // TODO(bartfab): Add a test once it becomes possible to simulate a user | 804 // TODO(bartfab): Add a test once it becomes possible to simulate a user |
788 // gesture. http://crbug.com/174178 | 805 // gesture. http://crbug.com/174178 |
789 if (enter_fullscreen && | 806 PrefService* prefs = |
790 !profile()->GetPrefs()->GetBoolean(prefs::kAppFullscreenAllowed)) { | 807 extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext( |
| 808 browser_context()); |
| 809 if (enter_fullscreen && !prefs->GetBoolean(prefs::kAppFullscreenAllowed)) { |
791 return; | 810 return; |
792 } | 811 } |
793 #endif | 812 #endif |
794 | 813 |
795 if (!IsExtensionWithPermissionOrSuggestInConsole( | 814 if (!IsExtensionWithPermissionOrSuggestInConsole( |
796 APIPermission::kFullscreen, | 815 APIPermission::kFullscreen, |
797 extension_, | 816 extension_, |
798 source->GetRenderViewHost())) { | 817 source->GetRenderViewHost())) { |
799 return; | 818 return; |
800 } | 819 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 rvh->Send(new ExtensionMsg_AddMessageToConsole( | 875 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
857 rvh->GetRoutingID(), level, message)); | 876 rvh->GetRoutingID(), level, message)); |
858 } | 877 } |
859 | 878 |
860 void ShellWindow::SaveWindowPosition() { | 879 void ShellWindow::SaveWindowPosition() { |
861 if (window_key_.empty()) | 880 if (window_key_.empty()) |
862 return; | 881 return; |
863 if (!native_app_window_) | 882 if (!native_app_window_) |
864 return; | 883 return; |
865 | 884 |
866 ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); | 885 ShellWindowGeometryCache* cache = |
| 886 ShellWindowGeometryCache::Get(browser_context()); |
867 | 887 |
868 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 888 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
869 bounds.Inset(native_app_window_->GetFrameInsets()); | 889 bounds.Inset(native_app_window_->GetFrameInsets()); |
870 gfx::Rect screen_bounds = | 890 gfx::Rect screen_bounds = |
871 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); | 891 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds).work_area(); |
872 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); | 892 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); |
873 cache->SaveGeometry(extension()->id(), | 893 cache->SaveGeometry(extension()->id(), |
874 window_key_, | 894 window_key_, |
875 bounds, | 895 bounds, |
876 screen_bounds, | 896 screen_bounds, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 if (params.bounds.width() == 0) | 932 if (params.bounds.width() == 0) |
913 params.bounds.set_width(kDefaultWidth); | 933 params.bounds.set_width(kDefaultWidth); |
914 if (params.bounds.height() == 0) | 934 if (params.bounds.height() == 0) |
915 params.bounds.set_height(kDefaultHeight); | 935 params.bounds.set_height(kDefaultHeight); |
916 | 936 |
917 // If left and top are left undefined, the native shell window will center | 937 // If left and top are left undefined, the native shell window will center |
918 // the window on the main screen in a platform-defined manner. | 938 // the window on the main screen in a platform-defined manner. |
919 | 939 |
920 // Load cached state if it exists. | 940 // Load cached state if it exists. |
921 if (!params.window_key.empty()) { | 941 if (!params.window_key.empty()) { |
922 ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); | 942 ShellWindowGeometryCache* cache = |
| 943 ShellWindowGeometryCache::Get(browser_context()); |
923 | 944 |
924 gfx::Rect cached_bounds; | 945 gfx::Rect cached_bounds; |
925 gfx::Rect cached_screen_bounds; | 946 gfx::Rect cached_screen_bounds; |
926 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; | 947 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; |
927 if (cache->GetGeometry(extension()->id(), params.window_key, | 948 if (cache->GetGeometry(extension()->id(), params.window_key, |
928 &cached_bounds, &cached_screen_bounds, | 949 &cached_bounds, &cached_screen_bounds, |
929 &cached_state)) { | 950 &cached_state)) { |
930 // App window has cached screen bounds, make sure it fits on screen in | 951 // App window has cached screen bounds, make sure it fits on screen in |
931 // case the screen resolution changed. | 952 // case the screen resolution changed. |
932 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 953 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
(...skipping 28 matching lines...) Expand all Loading... |
961 region.bounds.x(), | 982 region.bounds.x(), |
962 region.bounds.y(), | 983 region.bounds.y(), |
963 region.bounds.right(), | 984 region.bounds.right(), |
964 region.bounds.bottom(), | 985 region.bounds.bottom(), |
965 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 986 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
966 } | 987 } |
967 return sk_region; | 988 return sk_region; |
968 } | 989 } |
969 | 990 |
970 } // namespace apps | 991 } // namespace apps |
OLD | NEW |