OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/app_window.h" | 5 #include "apps/app_window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "apps/app_delegate.h" | 11 #include "apps/app_delegate.h" |
| 12 #include "apps/app_web_contents_helper.h" |
12 #include "apps/app_window_geometry_cache.h" | 13 #include "apps/app_window_geometry_cache.h" |
13 #include "apps/app_window_registry.h" | 14 #include "apps/app_window_registry.h" |
14 #include "apps/apps_client.h" | 15 #include "apps/apps_client.h" |
15 #include "apps/size_constraints.h" | 16 #include "apps/size_constraints.h" |
16 #include "apps/ui/native_app_window.h" | 17 #include "apps/ui/native_app_window.h" |
17 #include "apps/ui/web_contents_sizer.h" | 18 #include "apps/ui/web_contents_sizer.h" |
18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "base/values.h" | 22 #include "base/values.h" |
(...skipping 13 matching lines...) Expand all Loading... |
35 #include "content/public/browser/resource_dispatcher_host.h" | 36 #include "content/public/browser/resource_dispatcher_host.h" |
36 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
37 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
38 #include "content/public/common/media_stream_request.h" | 39 #include "content/public/common/media_stream_request.h" |
39 #include "extensions/browser/extension_registry.h" | 40 #include "extensions/browser/extension_registry.h" |
40 #include "extensions/browser/extension_system.h" | 41 #include "extensions/browser/extension_system.h" |
41 #include "extensions/browser/extensions_browser_client.h" | 42 #include "extensions/browser/extensions_browser_client.h" |
42 #include "extensions/browser/notification_types.h" | 43 #include "extensions/browser/notification_types.h" |
43 #include "extensions/browser/process_manager.h" | 44 #include "extensions/browser/process_manager.h" |
44 #include "extensions/browser/view_type_utils.h" | 45 #include "extensions/browser/view_type_utils.h" |
| 46 #include "extensions/common/draggable_region.h" |
45 #include "extensions/common/extension.h" | 47 #include "extensions/common/extension.h" |
46 #include "extensions/common/extension_messages.h" | |
47 #include "extensions/common/manifest_handlers/icons_handler.h" | 48 #include "extensions/common/manifest_handlers/icons_handler.h" |
48 #include "extensions/common/permissions/permissions_data.h" | 49 #include "extensions/common/permissions/permissions_data.h" |
49 #include "grit/theme_resources.h" | 50 #include "grit/theme_resources.h" |
50 #include "third_party/skia/include/core/SkRegion.h" | 51 #include "third_party/skia/include/core/SkRegion.h" |
51 #include "ui/base/resource/resource_bundle.h" | 52 #include "ui/base/resource/resource_bundle.h" |
52 #include "ui/gfx/screen.h" | 53 #include "ui/gfx/screen.h" |
53 | 54 |
54 #if !defined(OS_MACOSX) | 55 #if !defined(OS_MACOSX) |
55 #include "apps/pref_names.h" | 56 #include "apps/pref_names.h" |
56 #include "base/prefs/pref_service.h" | 57 #include "base/prefs/pref_service.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 286 |
286 // Windows cannot be always-on-top in fullscreen mode for security reasons. | 287 // Windows cannot be always-on-top in fullscreen mode for security reasons. |
287 cached_always_on_top_ = new_params.always_on_top; | 288 cached_always_on_top_ = new_params.always_on_top; |
288 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) | 289 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) |
289 new_params.always_on_top = false; | 290 new_params.always_on_top = false; |
290 | 291 |
291 requested_transparent_background_ = new_params.transparent_background; | 292 requested_transparent_background_ = new_params.transparent_background; |
292 | 293 |
293 native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params)); | 294 native_app_window_.reset(delegate_->CreateNativeAppWindow(this, new_params)); |
294 | 295 |
| 296 helper_.reset(new AppWebContentsHelper( |
| 297 browser_context_, extension_id_, web_contents, app_delegate_.get())); |
| 298 |
295 popup_manager_.reset( | 299 popup_manager_.reset( |
296 new web_modal::PopupManager(GetWebContentsModalDialogHost())); | 300 new web_modal::PopupManager(GetWebContentsModalDialogHost())); |
297 popup_manager_->RegisterWith(web_contents); | 301 popup_manager_->RegisterWith(web_contents); |
298 | 302 |
299 // Prevent the browser process from shutting down while this window exists. | 303 // Prevent the browser process from shutting down while this window exists. |
300 AppsClient::Get()->IncrementKeepAliveCount(); | 304 AppsClient::Get()->IncrementKeepAliveCount(); |
301 UpdateExtensionAppIcon(); | 305 UpdateExtensionAppIcon(); |
302 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); | 306 AppWindowRegistry::Get(browser_context_)->AddAppWindow(this); |
303 | 307 |
304 if (new_params.hidden) { | 308 if (new_params.hidden) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 registrar_.RemoveAll(); | 365 registrar_.RemoveAll(); |
362 | 366 |
363 // Remove shutdown prevention. | 367 // Remove shutdown prevention. |
364 AppsClient::Get()->DecrementKeepAliveCount(); | 368 AppsClient::Get()->DecrementKeepAliveCount(); |
365 } | 369 } |
366 | 370 |
367 void AppWindow::RequestMediaAccessPermission( | 371 void AppWindow::RequestMediaAccessPermission( |
368 content::WebContents* web_contents, | 372 content::WebContents* web_contents, |
369 const content::MediaStreamRequest& request, | 373 const content::MediaStreamRequest& request, |
370 const content::MediaResponseCallback& callback) { | 374 const content::MediaResponseCallback& callback) { |
371 const extensions::Extension* extension = GetExtension(); | 375 DCHECK_EQ(AppWindow::web_contents(), web_contents); |
372 if (!extension) | 376 helper_->RequestMediaAccessPermission(request, callback); |
373 return; | |
374 | |
375 app_delegate_->RequestMediaAccessPermission( | |
376 web_contents, request, callback, extension); | |
377 } | 377 } |
378 | 378 |
379 WebContents* AppWindow::OpenURLFromTab(WebContents* source, | 379 WebContents* AppWindow::OpenURLFromTab(WebContents* source, |
380 const content::OpenURLParams& params) { | 380 const content::OpenURLParams& params) { |
381 // Don't allow the current tab to be navigated. It would be nice to map all | 381 DCHECK_EQ(web_contents(), source); |
382 // anchor tags (even those without target="_blank") to new tabs, but right | 382 return helper_->OpenURLFromTab(params); |
383 // now we can't distinguish between those and <meta> refreshes or window.href | |
384 // navigations, which we don't want to allow. | |
385 // TOOD(mihaip): Can we check for user gestures instead? | |
386 WindowOpenDisposition disposition = params.disposition; | |
387 if (disposition == CURRENT_TAB) { | |
388 AddMessageToDevToolsConsole( | |
389 content::CONSOLE_MESSAGE_LEVEL_ERROR, | |
390 base::StringPrintf( | |
391 "Can't open same-window link to \"%s\"; try target=\"_blank\".", | |
392 params.url.spec().c_str())); | |
393 return NULL; | |
394 } | |
395 | |
396 // These dispositions aren't really navigations. | |
397 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || | |
398 disposition == IGNORE_ACTION) { | |
399 return NULL; | |
400 } | |
401 | |
402 WebContents* contents = | |
403 app_delegate_->OpenURLFromTab(browser_context_, source, params); | |
404 if (!contents) { | |
405 AddMessageToDevToolsConsole( | |
406 content::CONSOLE_MESSAGE_LEVEL_ERROR, | |
407 base::StringPrintf( | |
408 "Can't navigate to \"%s\"; apps do not support navigation.", | |
409 params.url.spec().c_str())); | |
410 } | |
411 | |
412 return contents; | |
413 } | 383 } |
414 | 384 |
415 void AppWindow::AddNewContents(WebContents* source, | 385 void AppWindow::AddNewContents(WebContents* source, |
416 WebContents* new_contents, | 386 WebContents* new_contents, |
417 WindowOpenDisposition disposition, | 387 WindowOpenDisposition disposition, |
418 const gfx::Rect& initial_pos, | 388 const gfx::Rect& initial_pos, |
419 bool user_gesture, | 389 bool user_gesture, |
420 bool* was_blocked) { | 390 bool* was_blocked) { |
421 DCHECK(new_contents->GetBrowserContext() == browser_context_); | 391 DCHECK(new_contents->GetBrowserContext() == browser_context_); |
422 app_delegate_->AddNewContents(browser_context_, | 392 app_delegate_->AddNewContents(browser_context_, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 Restore(); | 435 Restore(); |
466 return; | 436 return; |
467 } | 437 } |
468 | 438 |
469 native_app_window_->HandleKeyboardEvent(event); | 439 native_app_window_->HandleKeyboardEvent(event); |
470 } | 440 } |
471 | 441 |
472 void AppWindow::RequestToLockMouse(WebContents* web_contents, | 442 void AppWindow::RequestToLockMouse(WebContents* web_contents, |
473 bool user_gesture, | 443 bool user_gesture, |
474 bool last_unlocked_by_target) { | 444 bool last_unlocked_by_target) { |
475 const extensions::Extension* extension = GetExtension(); | 445 DCHECK_EQ(AppWindow::web_contents(), web_contents); |
476 if (!extension) | 446 helper_->RequestToLockMouse(); |
477 return; | |
478 | |
479 bool has_permission = IsExtensionWithPermissionOrSuggestInConsole( | |
480 APIPermission::kPointerLock, | |
481 extension, | |
482 web_contents->GetRenderViewHost()); | |
483 | |
484 web_contents->GotResponseToLockMouseRequest(has_permission); | |
485 } | 447 } |
486 | 448 |
487 bool AppWindow::PreHandleGestureEvent(WebContents* source, | 449 bool AppWindow::PreHandleGestureEvent(WebContents* source, |
488 const blink::WebGestureEvent& event) { | 450 const blink::WebGestureEvent& event) { |
489 // Disable pinch zooming in app windows. | 451 return AppWebContentsHelper::ShouldSuppressGestureEvent(event); |
490 return event.type == blink::WebGestureEvent::GesturePinchBegin || | |
491 event.type == blink::WebGestureEvent::GesturePinchUpdate || | |
492 event.type == blink::WebGestureEvent::GesturePinchEnd; | |
493 } | 452 } |
494 | 453 |
495 void AppWindow::DidFirstVisuallyNonEmptyPaint() { | 454 void AppWindow::DidFirstVisuallyNonEmptyPaint() { |
496 first_paint_complete_ = true; | 455 first_paint_complete_ = true; |
497 if (show_on_first_paint_) { | 456 if (show_on_first_paint_) { |
498 DCHECK(delayed_show_type_ == SHOW_ACTIVE || | 457 DCHECK(delayed_show_type_ == SHOW_ACTIVE || |
499 delayed_show_type_ == SHOW_INACTIVE); | 458 delayed_show_type_ == SHOW_INACTIVE); |
500 Show(delayed_show_type_); | 459 Show(delayed_show_type_); |
501 } | 460 } |
502 } | 461 } |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 } | 988 } |
1030 | 989 |
1031 bool AppWindow::IsWebContentsVisible(content::WebContents* web_contents) { | 990 bool AppWindow::IsWebContentsVisible(content::WebContents* web_contents) { |
1032 return app_delegate_->IsWebContentsVisible(web_contents); | 991 return app_delegate_->IsWebContentsVisible(web_contents); |
1033 } | 992 } |
1034 | 993 |
1035 WebContentsModalDialogHost* AppWindow::GetWebContentsModalDialogHost() { | 994 WebContentsModalDialogHost* AppWindow::GetWebContentsModalDialogHost() { |
1036 return native_app_window_.get(); | 995 return native_app_window_.get(); |
1037 } | 996 } |
1038 | 997 |
1039 void AppWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, | |
1040 const std::string& message) { | |
1041 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | |
1042 rvh->Send(new ExtensionMsg_AddMessageToConsole( | |
1043 rvh->GetRoutingID(), level, message)); | |
1044 } | |
1045 | |
1046 void AppWindow::SaveWindowPosition() { | 998 void AppWindow::SaveWindowPosition() { |
1047 if (window_key_.empty()) | 999 if (window_key_.empty()) |
1048 return; | 1000 return; |
1049 if (!native_app_window_) | 1001 if (!native_app_window_) |
1050 return; | 1002 return; |
1051 | 1003 |
1052 AppWindowGeometryCache* cache = | 1004 AppWindowGeometryCache* cache = |
1053 AppWindowGeometryCache::Get(browser_context()); | 1005 AppWindowGeometryCache::Get(browser_context()); |
1054 | 1006 |
1055 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 1007 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 region.bounds.x(), | 1106 region.bounds.x(), |
1155 region.bounds.y(), | 1107 region.bounds.y(), |
1156 region.bounds.right(), | 1108 region.bounds.right(), |
1157 region.bounds.bottom(), | 1109 region.bounds.bottom(), |
1158 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 1110 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
1159 } | 1111 } |
1160 return sk_region; | 1112 return sk_region; |
1161 } | 1113 } |
1162 | 1114 |
1163 } // namespace apps | 1115 } // namespace apps |
OLD | NEW |