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 "athena/extensions/chrome/athena_app_delegate.h" | 5 #include "athena/extensions/athena_app_delegate_base.h" |
6 | 6 |
7 #include "athena/activity/public/activity_factory.h" | 7 #include "athena/activity/public/activity_factory.h" |
8 #include "athena/activity/public/activity_manager.h" | 8 #include "athena/activity/public/activity_manager.h" |
9 #include "athena/env/public/athena_env.h" | 9 #include "athena/env/public/athena_env.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/stringprintf.h" | |
12 #include "chrome/browser/chrome_notification_types.h" | |
13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | |
14 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
15 #include "chrome/browser/file_select_helper.h" | |
16 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | |
17 #include "chrome/browser/platform_util.h" | |
18 #include "chrome/browser/profiles/profile.h" | |
19 #include "chrome/browser/shell_integration.h" | |
20 #include "chrome/browser/ui/browser.h" | |
21 #include "chrome/browser/ui/browser_dialogs.h" | |
22 #include "chrome/browser/ui/browser_tabstrip.h" | |
23 #include "chrome/browser/ui/browser_window.h" | |
24 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | |
25 #include "chrome/browser/ui/web_contents_sizer.h" | |
26 #include "chrome/common/extensions/chrome_extension_messages.h" | |
27 #include "content/public/browser/browser_context.h" | |
28 #include "content/public/browser/notification_service.h" | |
29 #include "content/public/browser/render_view_host.h" | |
30 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
31 #include "content/public/browser/web_contents_delegate.h" | 11 #include "content/public/browser/web_contents_delegate.h" |
32 #include "extensions/common/constants.h" | 12 #include "extensions/common/constants.h" |
33 #include "extensions/grit/extensions_browser_resources.h" | 13 #include "extensions/grit/extensions_browser_resources.h" |
| 14 #include "ui/aura/window.h" |
34 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
35 | 16 #include "ui/gfx/geometry/rect.h" |
36 #if defined(ENABLE_PRINTING) | |
37 #if defined(ENABLE_FULL_PRINTING) | |
38 #include "chrome/browser/printing/print_preview_message_handler.h" | |
39 #include "chrome/browser/printing/print_view_manager.h" | |
40 #else | |
41 #include "chrome/browser/printing/print_view_manager_basic.h" | |
42 #endif // defined(ENABLE_FULL_PRINTING) | |
43 #endif // defined(ENABLE_PRINTING) | |
44 | 17 |
45 namespace athena { | 18 namespace athena { |
46 namespace { | 19 namespace { |
47 | 20 |
48 content::WebContents* OpenURLInActivity( | 21 content::WebContents* OpenURLInActivity(content::BrowserContext* context, |
49 content::BrowserContext* context, | 22 const content::OpenURLParams& params) { |
50 const content::OpenURLParams& params) { | |
51 // Force all links to open in a new activity. | 23 // Force all links to open in a new activity. |
52 Activity* activity = ActivityFactory::Get()->CreateWebActivity( | 24 Activity* activity = ActivityFactory::Get()->CreateWebActivity( |
53 context, base::string16(), params.url); | 25 context, base::string16(), params.url); |
54 ActivityManager::Get()->AddActivity(activity); | 26 ActivityManager::Get()->AddActivity(activity); |
55 // TODO(oshima): Get the web cotnents from activity. | 27 // TODO(oshima): Get the web cotnents from activity. |
56 return NULL; | 28 return NULL; |
57 } | 29 } |
58 | 30 |
59 } // namespace | 31 } // namespace |
60 | 32 |
61 // This is a extra step to open a new Activity when a link is simply clicked | 33 // This is a extra step to open a new Activity when a link is simply clicked |
62 // on an app activity (which usually replaces the content). | 34 // on an app activity (which usually replaces the content). |
63 class AthenaAppDelegate::NewWindowContentsDelegate | 35 class AthenaAppDelegateBase::NewActivityContentsDelegate |
64 : public content::WebContentsDelegate { | 36 : public content::WebContentsDelegate { |
65 public: | 37 public: |
66 NewWindowContentsDelegate() {} | 38 NewActivityContentsDelegate() {} |
67 virtual ~NewWindowContentsDelegate() {} | 39 virtual ~NewActivityContentsDelegate() {} |
68 | 40 |
69 // content::WebContentsDelegate: | 41 // content::WebContentsDelegate: |
70 virtual content::WebContents* OpenURLFromTab( | 42 virtual content::WebContents* OpenURLFromTab( |
71 content::WebContents* source, | 43 content::WebContents* source, |
72 const content::OpenURLParams& params) OVERRIDE { | 44 const content::OpenURLParams& params) OVERRIDE { |
73 if (!source) | 45 if (!source) |
74 return NULL; | 46 return NULL; |
75 | |
76 return OpenURLInActivity(source->GetBrowserContext(), params); | 47 return OpenURLInActivity(source->GetBrowserContext(), params); |
77 } | 48 } |
78 | 49 |
79 private: | 50 private: |
80 DISALLOW_COPY_AND_ASSIGN(NewWindowContentsDelegate); | 51 DISALLOW_COPY_AND_ASSIGN(NewActivityContentsDelegate); |
81 }; | 52 }; |
82 | 53 |
83 AthenaAppDelegate::AthenaAppDelegate() | 54 AthenaAppDelegateBase::AthenaAppDelegateBase() |
84 : new_window_contents_delegate_(new NewWindowContentsDelegate()) { | 55 : new_window_contents_delegate_(new NewActivityContentsDelegate) { |
85 } | 56 } |
86 | 57 |
87 AthenaAppDelegate::~AthenaAppDelegate() { | 58 AthenaAppDelegateBase::~AthenaAppDelegateBase() { |
88 if (!terminating_callback_.is_null()) | 59 if (!terminating_callback_.is_null()) |
89 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_); | 60 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_); |
90 } | 61 } |
91 | 62 |
92 void AthenaAppDelegate::InitWebContents(content::WebContents* web_contents) { | 63 void AthenaAppDelegateBase::ResizeWebContents( |
93 FaviconTabHelper::CreateForWebContents(web_contents); | 64 content::WebContents* web_contents, |
94 | 65 const gfx::Size& size) { |
95 #if defined(ENABLE_PRINTING) | 66 aura::Window* window = web_contents->GetNativeView(); |
96 #if defined(ENABLE_FULL_PRINTING) | 67 window->SetBounds(gfx::Rect(window->bounds().origin(), size)); |
97 printing::PrintViewManager::CreateForWebContents(web_contents); | |
98 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents); | |
99 #else | |
100 printing::PrintViewManagerBasic::CreateForWebContents(web_contents); | |
101 #endif // defined(ENABLE_FULL_PRINTING) | |
102 #endif // defined(ENABLE_PRINTING) | |
103 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | |
104 web_contents); | |
105 } | 68 } |
106 | 69 |
107 void AthenaAppDelegate::ResizeWebContents(content::WebContents* web_contents, | 70 content::WebContents* AthenaAppDelegateBase::OpenURLFromTab( |
108 const gfx::Size& size) { | |
109 ::ResizeWebContents(web_contents, size); | |
110 } | |
111 | |
112 content::WebContents* AthenaAppDelegate::OpenURLFromTab( | |
113 content::BrowserContext* context, | 71 content::BrowserContext* context, |
114 content::WebContents* source, | 72 content::WebContents* source, |
115 const content::OpenURLParams& params) { | 73 const content::OpenURLParams& params) { |
116 return OpenURLInActivity(context, params); | 74 return OpenURLInActivity(context, params); |
117 } | 75 } |
118 | 76 |
119 void AthenaAppDelegate::AddNewContents(content::BrowserContext* context, | 77 void AthenaAppDelegateBase::AddNewContents(content::BrowserContext* context, |
120 content::WebContents* new_contents, | 78 content::WebContents* new_contents, |
121 WindowOpenDisposition disposition, | 79 WindowOpenDisposition disposition, |
122 const gfx::Rect& initial_pos, | 80 const gfx::Rect& initial_pos, |
123 bool user_gesture, | 81 bool user_gesture, |
124 bool* was_blocked) { | 82 bool* was_blocked) { |
125 new_contents->SetDelegate(new_window_contents_delegate_.get()); | 83 new_contents->SetDelegate(new_window_contents_delegate_.get()); |
126 } | 84 } |
127 | 85 |
128 content::ColorChooser* AthenaAppDelegate::ShowColorChooser( | 86 int AthenaAppDelegateBase::PreferredIconSize() { |
129 content::WebContents* web_contents, | |
130 SkColor initial_color) { | |
131 return chrome::ShowColorChooser(web_contents, initial_color); | |
132 } | |
133 | |
134 void AthenaAppDelegate::RunFileChooser( | |
135 content::WebContents* tab, | |
136 const content::FileChooserParams& params) { | |
137 FileSelectHelper::RunFileChooser(tab, params); | |
138 } | |
139 | |
140 void AthenaAppDelegate::RequestMediaAccessPermission( | |
141 content::WebContents* web_contents, | |
142 const content::MediaStreamRequest& request, | |
143 const content::MediaResponseCallback& callback, | |
144 const extensions::Extension* extension) { | |
145 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | |
146 web_contents, request, callback, extension); | |
147 } | |
148 | |
149 bool AthenaAppDelegate::CheckMediaAccessPermission( | |
150 content::WebContents* web_contents, | |
151 const GURL& security_origin, | |
152 content::MediaStreamType type, | |
153 const extensions::Extension* extension) { | |
154 return MediaCaptureDevicesDispatcher::GetInstance() | |
155 ->CheckMediaAccessPermission( | |
156 web_contents, security_origin, type, extension); | |
157 } | |
158 | |
159 int AthenaAppDelegate::PreferredIconSize() { | |
160 // TODO(oshima): Find out what to use. | 87 // TODO(oshima): Find out what to use. |
161 return extension_misc::EXTENSION_ICON_SMALL; | 88 return extension_misc::EXTENSION_ICON_SMALL; |
162 } | 89 } |
163 | 90 |
164 gfx::ImageSkia AthenaAppDelegate::GetAppDefaultIcon() { | 91 gfx::ImageSkia AthenaAppDelegateBase::GetAppDefaultIcon() { |
165 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 92 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
166 IDR_APP_DEFAULT_ICON); | 93 IDR_APP_DEFAULT_ICON); |
167 } | 94 } |
168 | 95 |
169 void AthenaAppDelegate::SetWebContentsBlocked( | 96 bool AthenaAppDelegateBase::IsWebContentsVisible( |
170 content::WebContents* web_contents, | 97 content::WebContents* web_contents) { |
171 bool blocked) { | 98 return web_contents->GetNativeView()->IsVisible(); |
172 // RenderViewHost may be NULL during shutdown. | |
173 content::RenderViewHost* host = web_contents->GetRenderViewHost(); | |
174 if (host) { | |
175 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(host->GetRoutingID(), | |
176 blocked)); | |
177 } | |
178 } | 99 } |
179 | 100 |
180 bool AthenaAppDelegate::IsWebContentsVisible( | 101 void AthenaAppDelegateBase::SetTerminatingCallback( |
181 content::WebContents* web_contents) { | 102 const base::Closure& callback) { |
182 return platform_util::IsVisible(web_contents->GetNativeView()); | |
183 } | |
184 | |
185 void AthenaAppDelegate::SetTerminatingCallback(const base::Closure& callback) { | |
186 if (!terminating_callback_.is_null()) | 103 if (!terminating_callback_.is_null()) |
187 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_); | 104 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_); |
188 terminating_callback_ = callback; | 105 terminating_callback_ = callback; |
189 if (!terminating_callback_.is_null()) | 106 if (!terminating_callback_.is_null()) |
190 AthenaEnv::Get()->AddTerminatingCallback(terminating_callback_); | 107 AthenaEnv::Get()->AddTerminatingCallback(terminating_callback_); |
191 } | 108 } |
192 | 109 |
193 } // namespace athena | 110 } // namespace athena |
OLD | NEW |