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 "apps/shell_window.h" |
6 | 6 |
7 #include "apps/shell_window_geometry_cache.h" | 7 #include "apps/shell_window_geometry_cache.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/app_window_contents.h" | 10 #include "chrome/browser/extensions/app_window_contents.h" |
11 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/extensions/image_loader.h" | 13 #include "chrome/browser/extensions/image_loader.h" |
14 #include "chrome/browser/extensions/shell_window_registry.h" | 14 #include "chrome/browser/extensions/shell_window_registry.h" |
15 #include "chrome/browser/extensions/suggest_permission_util.h" | 15 #include "chrome/browser/extensions/suggest_permission_util.h" |
16 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
17 #include "chrome/browser/file_select_helper.h" | |
18 #include "chrome/browser/lifetime/application_lifetime.h" | 16 #include "chrome/browser/lifetime/application_lifetime.h" |
19 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | |
20 #include "chrome/browser/platform_util.h" | |
21 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/sessions/session_id.h" | |
23 #include "chrome/browser/ui/browser.h" | |
24 #include "chrome/browser/ui/browser_dialogs.h" | |
25 #include "chrome/browser/ui/browser_finder.h" | |
26 #include "chrome/browser/ui/browser_tabstrip.h" | |
27 #include "chrome/browser/ui/browser_window.h" | |
28 #include "chrome/browser/ui/extensions/native_app_window.h" | 18 #include "chrome/browser/ui/extensions/native_app_window.h" |
29 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
30 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
31 #include "chrome/common/extensions/extension_constants.h" | 21 #include "chrome/common/extensions/extension_constants.h" |
32 #include "chrome/common/extensions/extension_messages.h" | 22 #include "chrome/common/extensions/extension_messages.h" |
33 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 23 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
34 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 24 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
35 #include "content/public/browser/invalidate_type.h" | 25 #include "content/public/browser/invalidate_type.h" |
36 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
37 #include "content/public/browser/notification_details.h" | 27 #include "content/public/browser/notification_details.h" |
38 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
40 #include "content/public/browser/notification_types.h" | 30 #include "content/public/browser/notification_types.h" |
41 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
42 #include "content/public/browser/resource_dispatcher_host.h" | 32 #include "content/public/browser/resource_dispatcher_host.h" |
43 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
44 #include "content/public/common/media_stream_request.h" | 34 #include "content/public/common/media_stream_request.h" |
45 #include "extensions/browser/view_type_utils.h" | 35 #include "extensions/browser/view_type_utils.h" |
46 #include "skia/ext/image_operations.h" | 36 #include "skia/ext/image_operations.h" |
47 #include "third_party/skia/include/core/SkRegion.h" | 37 #include "third_party/skia/include/core/SkRegion.h" |
48 #include "ui/gfx/image/image_skia.h" | 38 #include "ui/gfx/image/image_skia.h" |
49 | 39 |
50 #if defined(USE_ASH) | |
51 #include "ash/launcher/launcher_types.h" | |
52 #endif | |
53 | |
54 using content::ConsoleMessageLevel; | 40 using content::ConsoleMessageLevel; |
55 using content::WebContents; | 41 using content::WebContents; |
56 using extensions::APIPermission; | 42 using extensions::APIPermission; |
57 using web_modal::WebContentsModalDialogHost; | 43 using web_modal::WebContentsModalDialogHost; |
58 using web_modal::WebContentsModalDialogManager; | 44 using web_modal::WebContentsModalDialogManager; |
59 | 45 |
60 namespace { | 46 namespace { |
61 const int kDefaultWidth = 512; | 47 const int kDefaultWidth = 512; |
62 const int kDefaultHeight = 384; | 48 const int kDefaultHeight = 384; |
63 | 49 |
64 // The preferred icon size for displaying the app icon. | 50 } // namespace |
65 #if defined(USE_ASH) | |
66 const int kPreferredIconSize = ash::kLauncherPreferredSize; | |
67 #else | |
68 const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL; | |
69 #endif | |
70 | 51 |
71 static bool disable_external_open_for_testing_ = false; | 52 namespace apps { |
72 | |
73 class ShellWindowLinkDelegate : public content::WebContentsDelegate { | |
74 private: | |
75 virtual content::WebContents* OpenURLFromTab( | |
76 content::WebContents* source, | |
77 const content::OpenURLParams& params) OVERRIDE; | |
78 }; | |
79 | |
80 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( | |
81 content::WebContents* source, | |
82 const content::OpenURLParams& params) { | |
83 platform_util::OpenExternal(params.url); | |
84 delete source; | |
85 return NULL; | |
86 } | |
87 | |
88 } // namespace | |
89 | 53 |
90 ShellWindow::CreateParams::CreateParams() | 54 ShellWindow::CreateParams::CreateParams() |
91 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), | 55 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), |
92 frame(ShellWindow::FRAME_CHROME), | 56 frame(ShellWindow::FRAME_CHROME), |
93 transparent_background(false), | 57 transparent_background(false), |
94 bounds(INT_MIN, INT_MIN, 0, 0), | 58 bounds(INT_MIN, INT_MIN, 0, 0), |
95 creator_process_id(0), | 59 creator_process_id(0), |
96 state(ui::SHOW_STATE_DEFAULT), | 60 state(ui::SHOW_STATE_DEFAULT), |
97 hidden(false), | 61 hidden(false), |
98 resizable(true), | 62 resizable(true), |
99 focused(true) { | 63 focused(true) {} |
100 } | |
101 | 64 |
102 ShellWindow::CreateParams::~CreateParams() { | 65 ShellWindow::CreateParams::~CreateParams() {} |
103 } | 66 |
67 ShellWindow::Delegate::~Delegate() {} | |
104 | 68 |
105 ShellWindow* ShellWindow::Create(Profile* profile, | 69 ShellWindow* ShellWindow::Create(Profile* profile, |
70 Delegate* delegate, | |
106 const extensions::Extension* extension, | 71 const extensions::Extension* extension, |
107 const GURL& url, | 72 const GURL& url, |
108 const CreateParams& params) { | 73 const CreateParams& params) { |
109 // This object will delete itself when the window is closed. | 74 // This object will delete itself when the window is closed. |
110 ShellWindow* window = new ShellWindow(profile, extension); | 75 ShellWindow* window = new ShellWindow(profile, delegate, extension); |
111 window->Init(url, new AppWindowContents(window), params); | 76 window->Init(url, new AppWindowContents(window), params); |
112 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); | 77 extensions::ShellWindowRegistry::Get(profile)->AddShellWindow(window); |
113 return window; | 78 return window; |
114 } | 79 } |
115 | 80 |
116 ShellWindow::ShellWindow(Profile* profile, | 81 ShellWindow::ShellWindow(Profile* profile, |
82 Delegate* delegate, | |
117 const extensions::Extension* extension) | 83 const extensions::Extension* extension) |
118 : profile_(profile), | 84 : profile_(profile), |
119 extension_(extension), | 85 extension_(extension), |
120 extension_id_(extension->id()), | 86 extension_id_(extension->id()), |
121 window_type_(WINDOW_TYPE_DEFAULT), | 87 window_type_(WINDOW_TYPE_DEFAULT), |
88 delegate_(delegate), | |
122 image_loader_ptr_factory_(this), | 89 image_loader_ptr_factory_(this), |
123 fullscreen_for_window_api_(false), | 90 fullscreen_for_window_api_(false), |
124 fullscreen_for_tab_(false) { | 91 fullscreen_for_tab_(false) { |
125 } | 92 } |
126 | 93 |
127 void ShellWindow::Init(const GURL& url, | 94 void ShellWindow::Init(const GURL& url, |
128 ShellWindowContents* shell_window_contents, | 95 ShellWindowContents* shell_window_contents, |
129 const CreateParams& params) { | 96 const CreateParams& params) { |
130 // Initialize the render interface and web contents | 97 // Initialize the render interface and web contents |
131 shell_window_contents_.reset(shell_window_contents); | 98 shell_window_contents_.reset(shell_window_contents); |
132 shell_window_contents_->Initialize(profile(), url); | 99 shell_window_contents_->Initialize(profile(), url); |
133 WebContents* web_contents = shell_window_contents_->GetWebContents(); | 100 WebContents* web_contents = shell_window_contents_->GetWebContents(); |
101 delegate_->InitWebContents(web_contents); | |
134 WebContentsModalDialogManager::CreateForWebContents(web_contents); | 102 WebContentsModalDialogManager::CreateForWebContents(web_contents); |
135 FaviconTabHelper::CreateForWebContents(web_contents); | |
136 | 103 |
137 web_contents->SetDelegate(this); | 104 web_contents->SetDelegate(this); |
138 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 105 WebContentsModalDialogManager::FromWebContents(web_contents)-> |
139 set_delegate(this); | 106 set_delegate(this); |
140 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL); | 107 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL); |
141 | 108 |
142 // Initialize the window | 109 // Initialize the window |
143 window_type_ = params.window_type; | 110 window_type_ = params.window_type; |
144 | 111 |
145 gfx::Rect bounds = params.bounds; | 112 gfx::Rect bounds = params.bounds; |
146 | 113 |
147 if (bounds.width() == 0) | 114 if (bounds.width() == 0) |
148 bounds.set_width(kDefaultWidth); | 115 bounds.set_width(kDefaultWidth); |
149 if (bounds.height() == 0) | 116 if (bounds.height() == 0) |
150 bounds.set_height(kDefaultHeight); | 117 bounds.set_height(kDefaultHeight); |
151 | 118 |
152 // If left and top are left undefined, the native shell window will center | 119 // If left and top are left undefined, the native shell window will center |
153 // the window on the main screen in a platform-defined manner. | 120 // the window on the main screen in a platform-defined manner. |
154 | 121 |
155 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; | 122 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; |
156 if (!params.window_key.empty()) { | 123 if (!params.window_key.empty()) { |
157 window_key_ = params.window_key; | 124 window_key_ = params.window_key; |
158 | 125 |
159 apps::ShellWindowGeometryCache* cache = | 126 ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); |
160 apps::ShellWindowGeometryCache::Get(profile()); | |
161 | 127 |
162 gfx::Rect cached_bounds; | 128 gfx::Rect cached_bounds; |
163 if (cache->GetGeometry(extension()->id(), params.window_key, | 129 if (cache->GetGeometry(extension()->id(), params.window_key, |
164 &cached_bounds, &cached_state)) { | 130 &cached_bounds, &cached_state)) { |
165 bounds = cached_bounds; | 131 bounds = cached_bounds; |
166 } | 132 } |
167 } | 133 } |
168 | 134 |
169 CreateParams new_params = params; | 135 CreateParams new_params = params; |
170 | 136 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 | 179 |
214 // When the render view host is changed, the native window needs to know | 180 // When the render view host is changed, the native window needs to know |
215 // about it in case it has any setup to do to make the renderer appear | 181 // about it in case it has any setup to do to make the renderer appear |
216 // properly. In particular, on Windows, the view's clickthrough region needs | 182 // properly. In particular, on Windows, the view's clickthrough region needs |
217 // to be set. | 183 // to be set. |
218 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 184 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
219 content::Source<content::NavigationController>( | 185 content::Source<content::NavigationController>( |
220 &web_contents->GetController())); | 186 &web_contents->GetController())); |
221 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 187 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
222 content::Source<Profile>(profile_)); | 188 content::Source<Profile>(profile_)); |
223 // Close when the browser is exiting. | 189 // Close when the browser process is exiting. |
224 // TODO(mihaip): we probably don't want this in the long run (when platform | |
225 // apps are no longer tied to the browser process). | |
226 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 190 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
227 content::NotificationService::AllSources()); | 191 content::NotificationService::AllSources()); |
228 | 192 |
229 shell_window_contents_->LoadContents(params.creator_process_id); | 193 shell_window_contents_->LoadContents(params.creator_process_id); |
230 | 194 |
231 // Prevent the browser process from shutting down while this window is open. | 195 // Prevent the browser process from shutting down while this window is open. |
232 chrome::StartKeepAlive(); | 196 chrome::StartKeepAlive(); |
233 | 197 |
234 UpdateExtensionAppIcon(); | 198 UpdateExtensionAppIcon(); |
235 } | 199 } |
236 | 200 |
237 ShellWindow::~ShellWindow() { | 201 ShellWindow::~ShellWindow() { |
238 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the | 202 // Unregister now to prevent getting NOTIFICATION_APP_TERMINATING if we're the |
239 // last window open. | 203 // last window open. |
240 registrar_.RemoveAll(); | 204 registrar_.RemoveAll(); |
241 | 205 |
242 // Remove shutdown prevention. | 206 // Remove shutdown prevention. |
243 chrome::EndKeepAlive(); | 207 chrome::EndKeepAlive(); |
244 } | 208 } |
245 | 209 |
246 void ShellWindow::RequestMediaAccessPermission( | 210 void ShellWindow::RequestMediaAccessPermission( |
247 content::WebContents* web_contents, | 211 content::WebContents* web_contents, |
248 const content::MediaStreamRequest& request, | 212 const content::MediaStreamRequest& request, |
249 const content::MediaResponseCallback& callback) { | 213 const content::MediaResponseCallback& callback) { |
250 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | 214 delegate_->RequestMediaAccessPermission(web_contents, request, callback, |
251 web_contents, request, callback, extension()); | 215 extension()); |
252 } | 216 } |
253 | 217 |
254 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, | 218 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, |
255 const content::OpenURLParams& params) { | 219 const content::OpenURLParams& params) { |
256 // Don't allow the current tab to be navigated. It would be nice to map all | 220 // Don't allow the current tab to be navigated. It would be nice to map all |
257 // anchor tags (even those without target="_blank") to new tabs, but right | 221 // anchor tags (even those without target="_blank") to new tabs, but right |
258 // now we can't distinguish between those and <meta> refreshes or window.href | 222 // now we can't distinguish between those and <meta> refreshes or window.href |
259 // navigations, which we don't want to allow. | 223 // navigations, which we don't want to allow. |
260 // TOOD(mihaip): Can we check for user gestures instead? | 224 // TOOD(mihaip): Can we check for user gestures instead? |
261 WindowOpenDisposition disposition = params.disposition; | 225 WindowOpenDisposition disposition = params.disposition; |
262 if (disposition == CURRENT_TAB) { | 226 if (disposition == CURRENT_TAB) { |
263 AddMessageToDevToolsConsole( | 227 AddMessageToDevToolsConsole( |
264 content::CONSOLE_MESSAGE_LEVEL_ERROR, | 228 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
265 base::StringPrintf( | 229 base::StringPrintf( |
266 "Can't open same-window link to \"%s\"; try target=\"_blank\".", | 230 "Can't open same-window link to \"%s\"; try target=\"_blank\".", |
267 params.url.spec().c_str())); | 231 params.url.spec().c_str())); |
268 return NULL; | 232 return NULL; |
269 } | 233 } |
270 | 234 |
271 // These dispositions aren't really navigations. | 235 // These dispositions aren't really navigations. |
272 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || | 236 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || |
273 disposition == IGNORE_ACTION) { | 237 disposition == IGNORE_ACTION) { |
274 return NULL; | 238 return NULL; |
275 } | 239 } |
276 | 240 |
277 // Force all links to open in a new tab, even if they were trying to open a | 241 WebContents* contents = delegate_->OpenURLFromTab(profile_, source, |
278 // window. | 242 params); |
279 chrome::NavigateParams new_tab_params( | 243 if (!contents) { |
280 static_cast<Browser*>(NULL), params.url, params.transition); | |
281 new_tab_params.disposition = | |
282 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | |
283 new_tab_params.initiating_profile = profile_; | |
284 chrome::Navigate(&new_tab_params); | |
285 | |
286 if (!new_tab_params.target_contents) { | |
287 AddMessageToDevToolsConsole( | 244 AddMessageToDevToolsConsole( |
288 content::CONSOLE_MESSAGE_LEVEL_ERROR, | 245 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
289 base::StringPrintf( | 246 base::StringPrintf( |
290 "Can't navigate to \"%s\"; apps do not support navigation.", | 247 "Can't navigate to \"%s\"; apps do not support navigation.", |
291 params.url.spec().c_str())); | 248 params.url.spec().c_str())); |
292 } | 249 } |
293 | 250 |
294 return new_tab_params.target_contents; | 251 return contents; |
295 } | 252 } |
296 | 253 |
297 void ShellWindow::AddNewContents(WebContents* source, | 254 void ShellWindow::AddNewContents(WebContents* source, |
298 WebContents* new_contents, | 255 WebContents* new_contents, |
299 WindowOpenDisposition disposition, | 256 WindowOpenDisposition disposition, |
300 const gfx::Rect& initial_pos, | 257 const gfx::Rect& initial_pos, |
301 bool user_gesture, | 258 bool user_gesture, |
302 bool* was_blocked) { | 259 bool* was_blocked) { |
303 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == | 260 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
304 profile_); | 261 profile_); |
305 #if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) | 262 delegate_->AddNewContents(profile_, new_contents, disposition, |
306 if (disable_external_open_for_testing_) { | 263 initial_pos, user_gesture, was_blocked); |
307 Browser* browser = | |
308 chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop()); | |
309 // Force all links to open in a new tab, even if they were trying to open a | |
310 // new window. | |
311 disposition = | |
312 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | |
313 chrome::AddWebContents(browser, NULL, new_contents, disposition, | |
314 initial_pos, user_gesture, was_blocked); | |
315 } else { | |
316 new_contents->SetDelegate(new ShellWindowLinkDelegate()); | |
317 } | |
318 #else | |
319 Browser* browser = | |
320 chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop()); | |
321 // Force all links to open in a new tab, even if they were trying to open a | |
322 // new window. | |
323 disposition = | |
324 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | |
325 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, | |
326 user_gesture, was_blocked); | |
327 #endif | |
328 } | 264 } |
329 | 265 |
330 void ShellWindow::HandleKeyboardEvent( | 266 void ShellWindow::HandleKeyboardEvent( |
331 WebContents* source, | 267 WebContents* source, |
332 const content::NativeWebKeyboardEvent& event) { | 268 const content::NativeWebKeyboardEvent& event) { |
333 native_app_window_->HandleKeyboardEvent(event); | 269 native_app_window_->HandleKeyboardEvent(event); |
334 } | 270 } |
335 | 271 |
336 void ShellWindow::RequestToLockMouse(WebContents* web_contents, | 272 void ShellWindow::RequestToLockMouse(WebContents* web_contents, |
337 bool user_gesture, | 273 bool user_gesture, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 | 333 |
398 string16 ShellWindow::GetTitle() const { | 334 string16 ShellWindow::GetTitle() const { |
399 // WebContents::GetTitle() will return the page's URL if there's no <title> | 335 // WebContents::GetTitle() will return the page's URL if there's no <title> |
400 // specified. However, we'd prefer to show the name of the extension in that | 336 // specified. However, we'd prefer to show the name of the extension in that |
401 // case, so we directly inspect the NavigationEntry's title. | 337 // case, so we directly inspect the NavigationEntry's title. |
402 if (!web_contents() || | 338 if (!web_contents() || |
403 !web_contents()->GetController().GetActiveEntry() || | 339 !web_contents()->GetController().GetActiveEntry() || |
404 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) | 340 web_contents()->GetController().GetActiveEntry()->GetTitle().empty()) |
405 return UTF8ToUTF16(extension()->name()); | 341 return UTF8ToUTF16(extension()->name()); |
406 string16 title = web_contents()->GetTitle(); | 342 string16 title = web_contents()->GetTitle(); |
407 Browser::FormatTitleForDisplay(&title); | 343 size_t current_index = 0; |
344 size_t match_index; | |
345 while ((match_index = title.find(L'\n', current_index)) != string16::npos) { | |
miket_OOO
2013/06/14 20:07:51
I think this deletes newlines. If I'm correct, ple
benwells
2013/06/19 09:00:21
Done. I've also made it strip newlines from the ex
| |
346 title.replace(match_index, 1, string16()); | |
347 current_index = match_index; | |
348 } | |
408 return title; | 349 return title; |
409 } | 350 } |
410 | 351 |
411 void ShellWindow::SetAppIconUrl(const GURL& url) { | 352 void ShellWindow::SetAppIconUrl(const GURL& url) { |
412 // Avoid using any previous app icons were are being downloaded. | 353 // Avoid using any previous app icons were are being downloaded. |
413 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 354 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
414 | 355 |
415 app_icon_url_ = url; | 356 app_icon_url_ = url; |
416 web_contents()->DownloadImage( | 357 web_contents()->DownloadImage( |
417 url, true, kPreferredIconSize, | 358 url, true, delegate_->PreferredIconSize(), |
418 base::Bind(&ShellWindow::DidDownloadFavicon, | 359 base::Bind(&ShellWindow::DidDownloadFavicon, |
419 image_loader_ptr_factory_.GetWeakPtr())); | 360 image_loader_ptr_factory_.GetWeakPtr())); |
420 } | 361 } |
421 | 362 |
422 void ShellWindow::UpdateDraggableRegions( | 363 void ShellWindow::UpdateDraggableRegions( |
423 const std::vector<extensions::DraggableRegion>& regions) { | 364 const std::vector<extensions::DraggableRegion>& regions) { |
424 native_app_window_->UpdateDraggableRegions(regions); | 365 native_app_window_->UpdateDraggableRegions(regions); |
425 } | 366 } |
426 | 367 |
427 void ShellWindow::UpdateAppIcon(const gfx::Image& image) { | 368 void ShellWindow::UpdateAppIcon(const gfx::Image& image) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 const GURL& image_url, | 408 const GURL& image_url, |
468 int requested_size, | 409 int requested_size, |
469 const std::vector<SkBitmap>& bitmaps) { | 410 const std::vector<SkBitmap>& bitmaps) { |
470 if (image_url != app_icon_url_ || bitmaps.empty()) | 411 if (image_url != app_icon_url_ || bitmaps.empty()) |
471 return; | 412 return; |
472 | 413 |
473 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap | 414 // Bitmaps are ordered largest to smallest. Choose the smallest bitmap |
474 // whose height >= the preferred size. | 415 // whose height >= the preferred size. |
475 int largest_index = 0; | 416 int largest_index = 0; |
476 for (size_t i = 1; i < bitmaps.size(); ++i) { | 417 for (size_t i = 1; i < bitmaps.size(); ++i) { |
477 if (bitmaps[i].height() < kPreferredIconSize) | 418 if (bitmaps[i].height() < delegate_->PreferredIconSize()) |
478 break; | 419 break; |
479 largest_index = i; | 420 largest_index = i; |
480 } | 421 } |
481 const SkBitmap& largest = bitmaps[largest_index]; | 422 const SkBitmap& largest = bitmaps[largest_index]; |
482 UpdateAppIcon(gfx::Image::CreateFrom1xBitmap(largest)); | 423 UpdateAppIcon(gfx::Image::CreateFrom1xBitmap(largest)); |
483 } | 424 } |
484 | 425 |
485 void ShellWindow::UpdateExtensionAppIcon() { | 426 void ShellWindow::UpdateExtensionAppIcon() { |
486 // Avoid using any previous app icons were are being downloaded. | 427 // Avoid using any previous app icons were are being downloaded. |
487 image_loader_ptr_factory_.InvalidateWeakPtrs(); | 428 image_loader_ptr_factory_.InvalidateWeakPtrs(); |
488 | 429 |
489 // Enqueue OnImageLoaded callback. | 430 // Enqueue OnImageLoaded callback. |
490 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile()); | 431 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile()); |
491 loader->LoadImageAsync( | 432 loader->LoadImageAsync( |
492 extension(), | 433 extension(), |
493 extensions::IconsInfo::GetIconResource(extension(), | 434 extensions::IconsInfo::GetIconResource(extension(), |
494 kPreferredIconSize, | 435 delegate_->PreferredIconSize(), |
495 ExtensionIconSet::MATCH_BIGGER), | 436 ExtensionIconSet::MATCH_BIGGER), |
496 gfx::Size(kPreferredIconSize, kPreferredIconSize), | 437 gfx::Size(delegate_->PreferredIconSize(), delegate_->PreferredIconSize()), |
497 base::Bind(&ShellWindow::OnImageLoaded, | 438 base::Bind(&ShellWindow::OnImageLoaded, |
498 image_loader_ptr_factory_.GetWeakPtr())); | 439 image_loader_ptr_factory_.GetWeakPtr())); |
499 } | 440 } |
500 | 441 |
501 void ShellWindow::CloseContents(WebContents* contents) { | 442 void ShellWindow::CloseContents(WebContents* contents) { |
502 native_app_window_->Close(); | 443 native_app_window_->Close(); |
503 } | 444 } |
504 | 445 |
505 bool ShellWindow::ShouldSuppressDialogs() { | 446 bool ShellWindow::ShouldSuppressDialogs() { |
506 return true; | 447 return true; |
507 } | 448 } |
508 | 449 |
509 content::ColorChooser* ShellWindow::OpenColorChooser(WebContents* web_contents, | 450 content::ColorChooser* ShellWindow::OpenColorChooser(WebContents* web_contents, |
510 SkColor initial_color) { | 451 SkColor initial_color) { |
511 return chrome::ShowColorChooser(web_contents, initial_color); | 452 return delegate_->ShowColorChooser(web_contents, initial_color); |
512 } | 453 } |
513 | 454 |
514 void ShellWindow::RunFileChooser(WebContents* tab, | 455 void ShellWindow::RunFileChooser(WebContents* tab, |
515 const content::FileChooserParams& params) { | 456 const content::FileChooserParams& params) { |
516 if (window_type_is_panel()) { | 457 if (window_type_is_panel()) { |
517 // Panels can't host a file dialog, abort. TODO(stevenjb): allow file | 458 // Panels can't host a file dialog, abort. TODO(stevenjb): allow file |
518 // dialogs to be unhosted but still close with the owning web contents. | 459 // dialogs to be unhosted but still close with the owning web contents. |
519 // crbug.com/172502. | 460 // crbug.com/172502. |
520 LOG(WARNING) << "File dialog opened by panel."; | 461 LOG(WARNING) << "File dialog opened by panel."; |
521 return; | 462 return; |
522 } | 463 } |
523 FileSelectHelper::RunFileChooser(tab, params); | 464 |
465 delegate_->RunFileChooser(tab, params); | |
524 } | 466 } |
525 | 467 |
526 bool ShellWindow::IsPopupOrPanel(const WebContents* source) const { | 468 bool ShellWindow::IsPopupOrPanel(const WebContents* source) const { |
527 return true; | 469 return true; |
528 } | 470 } |
529 | 471 |
530 void ShellWindow::MoveContents(WebContents* source, const gfx::Rect& pos) { | 472 void ShellWindow::MoveContents(WebContents* source, const gfx::Rect& pos) { |
531 native_app_window_->SetBounds(pos); | 473 native_app_window_->SetBounds(pos); |
532 } | 474 } |
533 | 475 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 break; | 524 break; |
583 } | 525 } |
584 case chrome::NOTIFICATION_APP_TERMINATING: | 526 case chrome::NOTIFICATION_APP_TERMINATING: |
585 native_app_window_->Close(); | 527 native_app_window_->Close(); |
586 break; | 528 break; |
587 default: | 529 default: |
588 NOTREACHED() << "Received unexpected notification"; | 530 NOTREACHED() << "Received unexpected notification"; |
589 } | 531 } |
590 } | 532 } |
591 | 533 |
534 void ShellWindow::SetWebContentsBlocked(content::WebContents* web_contents, | |
535 bool blocked) { | |
536 delegate_->SetWebContentsBlocked(web_contents, blocked); | |
537 } | |
538 | |
539 bool ShellWindow::IsWebContentsVisible(content::WebContents* web_contents) { | |
540 return delegate_->IsWebContentsVisible(web_contents); | |
541 } | |
542 | |
592 extensions::ActiveTabPermissionGranter* | 543 extensions::ActiveTabPermissionGranter* |
593 ShellWindow::GetActiveTabPermissionGranter() { | 544 ShellWindow::GetActiveTabPermissionGranter() { |
594 // Shell windows don't support the activeTab permission. | 545 // Shell windows don't support the activeTab permission. |
595 return NULL; | 546 return NULL; |
596 } | 547 } |
597 | 548 |
598 WebContentsModalDialogHost* ShellWindow::GetWebContentsModalDialogHost() { | 549 WebContentsModalDialogHost* ShellWindow::GetWebContentsModalDialogHost() { |
599 return native_app_window_.get(); | 550 return native_app_window_.get(); |
600 } | 551 } |
601 | 552 |
602 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, | 553 void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level, |
603 const std::string& message) { | 554 const std::string& message) { |
604 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); | 555 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
605 rvh->Send(new ExtensionMsg_AddMessageToConsole( | 556 rvh->Send(new ExtensionMsg_AddMessageToConsole( |
606 rvh->GetRoutingID(), level, message)); | 557 rvh->GetRoutingID(), level, message)); |
607 } | 558 } |
608 | 559 |
609 void ShellWindow::SaveWindowPosition() { | 560 void ShellWindow::SaveWindowPosition() { |
610 if (window_key_.empty()) | 561 if (window_key_.empty()) |
611 return; | 562 return; |
612 if (!native_app_window_) | 563 if (!native_app_window_) |
613 return; | 564 return; |
614 | 565 |
615 apps::ShellWindowGeometryCache* cache = | 566 ShellWindowGeometryCache* cache = ShellWindowGeometryCache::Get(profile()); |
616 apps::ShellWindowGeometryCache::Get(profile()); | |
617 | 567 |
618 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 568 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
619 bounds.Inset(native_app_window_->GetFrameInsets()); | 569 bounds.Inset(native_app_window_->GetFrameInsets()); |
620 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); | 570 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); |
621 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); | 571 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); |
622 } | 572 } |
623 | 573 |
624 // static | 574 // static |
625 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( | 575 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( |
626 const std::vector<extensions::DraggableRegion>& regions) { | 576 const std::vector<extensions::DraggableRegion>& regions) { |
627 SkRegion* sk_region = new SkRegion; | 577 SkRegion* sk_region = new SkRegion; |
628 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | 578 for (std::vector<extensions::DraggableRegion>::const_iterator iter = |
629 regions.begin(); | 579 regions.begin(); |
630 iter != regions.end(); ++iter) { | 580 iter != regions.end(); ++iter) { |
631 const extensions::DraggableRegion& region = *iter; | 581 const extensions::DraggableRegion& region = *iter; |
632 sk_region->op( | 582 sk_region->op( |
633 region.bounds.x(), | 583 region.bounds.x(), |
634 region.bounds.y(), | 584 region.bounds.y(), |
635 region.bounds.right(), | 585 region.bounds.right(), |
636 region.bounds.bottom(), | 586 region.bounds.bottom(), |
637 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 587 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
638 } | 588 } |
639 return sk_region; | 589 return sk_region; |
640 } | 590 } |
641 | 591 |
642 void ShellWindow::DisableExternalOpenForTesting() { | 592 } // namespace apps |
643 disable_external_open_for_testing_ = true; | |
644 } | |
645 | |
OLD | NEW |