Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: chrome/browser/extensions/tab_helper.cc

Issue 64853004: Use high resolution icons where possible for streamlined hosted app icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser_experiment_create_app_from_page
Patch Set: fix tests for linux Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/tab_helper.h ('k') | chrome/browser/favicon/favicon_tab_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/extensions/tab_helper.h" 5 #include "chrome/browser/extensions/tab_helper.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/activity_log/activity_log.h" 11 #include "chrome/browser/extensions/activity_log/activity_log.h"
11 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" 12 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
12 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" 13 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h"
13 #include "chrome/browser/extensions/crx_installer.h" 14 #include "chrome/browser/extensions/crx_installer.h"
14 #include "chrome/browser/extensions/error_console/error_console.h" 15 #include "chrome/browser/extensions/error_console/error_console.h"
15 #include "chrome/browser/extensions/extension_action.h" 16 #include "chrome/browser/extensions/extension_action.h"
16 #include "chrome/browser/extensions/extension_action_manager.h" 17 #include "chrome/browser/extensions/extension_action_manager.h"
17 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_system.h" 19 #include "chrome/browser/extensions/extension_system.h"
19 #include "chrome/browser/extensions/extension_tab_util.h" 20 #include "chrome/browser/extensions/extension_tab_util.h"
21 #include "chrome/browser/extensions/favicon_downloader.h"
20 #include "chrome/browser/extensions/image_loader.h" 22 #include "chrome/browser/extensions/image_loader.h"
21 #include "chrome/browser/extensions/page_action_controller.h" 23 #include "chrome/browser/extensions/page_action_controller.h"
22 #include "chrome/browser/extensions/script_badge_controller.h" 24 #include "chrome/browser/extensions/script_badge_controller.h"
23 #include "chrome/browser/extensions/script_bubble_controller.h" 25 #include "chrome/browser/extensions/script_bubble_controller.h"
24 #include "chrome/browser/extensions/script_executor.h" 26 #include "chrome/browser/extensions/script_executor.h"
25 #include "chrome/browser/extensions/webstore_inline_installer.h" 27 #include "chrome/browser/extensions/webstore_inline_installer.h"
26 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" 28 #include "chrome/browser/extensions/webstore_inline_installer_factory.h"
27 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/sessions/session_id.h" 30 #include "chrome/browser/sessions/session_id.h"
29 #include "chrome/browser/sessions/session_tab_helper.h" 31 #include "chrome/browser/sessions/session_tab_helper.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 OnContentScriptsExecuting) 274 OnContentScriptsExecuting)
273 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, 275 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange,
274 OnWatchedPageChange) 276 OnWatchedPageChange)
275 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded, 277 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded,
276 OnDetailedConsoleMessageAdded) 278 OnDetailedConsoleMessageAdded)
277 IPC_MESSAGE_UNHANDLED(handled = false) 279 IPC_MESSAGE_UNHANDLED(handled = false)
278 IPC_END_MESSAGE_MAP() 280 IPC_END_MESSAGE_MAP()
279 return handled; 281 return handled;
280 } 282 }
281 283
284 void TabHelper::CreateHostedApp() {
285 // Add urls from the WebApplicationInfo.
286 std::vector<GURL> web_app_info_icon_urls;
287 for (std::vector<WebApplicationInfo::IconInfo>::const_iterator it =
288 web_app_info_.icons.begin();
289 it != web_app_info_.icons.end(); ++it) {
290 if (it->url.is_valid())
291 web_app_info_icon_urls.push_back(it->url);
292 }
293
294 favicon_downloader_.reset(
295 new FaviconDownloader(web_contents(),
296 web_app_info_icon_urls,
297 base::Bind(&TabHelper::FinishCreateHostedApp,
298 base::Unretained(this))));
299 favicon_downloader_->Start();
300 }
301
302 void TabHelper::FinishCreateHostedApp(
303 bool success,
304 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) {
305 // The tab has navigated away during the icon download. Cancel the hosted app
306 // creation.
307 if (!success) {
308 favicon_downloader_.reset();
309 return;
310 }
311
312 WebApplicationInfo install_info(web_app_info_);
313 if (install_info.app_url.is_empty())
314 install_info.app_url = web_contents()->GetURL();
315
316 if (install_info.title.empty())
317 install_info.title = web_contents()->GetTitle();
318 if (install_info.title.empty())
319 install_info.title = UTF8ToUTF16(install_info.app_url.spec());
320
321 install_info.urls.push_back(install_info.app_url);
322 install_info.is_bookmark_app = true;
323
324 // Add the downloaded icons.
325 for (FaviconDownloader::FaviconMap::const_iterator map_it = bitmaps.begin();
326 map_it != bitmaps.end(); ++map_it) {
327 for (std::vector<SkBitmap>::const_iterator bitmap_it =
328 map_it->second.begin();
329 bitmap_it != map_it->second.end(); ++bitmap_it) {
330 if (!bitmap_it->empty()) {
331 WebApplicationInfo::IconInfo icon_info;
332 icon_info.data = *bitmap_it;
333 icon_info.width = icon_info.data.width();
334 icon_info.height = icon_info.data.height();
335 install_info.icons.push_back(icon_info);
336 }
337 }
338 }
339
340 Profile* profile =
341 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
342 scoped_refptr<extensions::CrxInstaller> installer(
343 extensions::CrxInstaller::CreateSilent(profile->GetExtensionService()));
344 installer->set_error_on_unsupported_requirements(true);
345 installer->InstallWebApp(install_info);
346 favicon_downloader_.reset();
347 }
348
282 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, 349 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents,
283 WebContents* new_web_contents) { 350 WebContents* new_web_contents) {
284 // When the WebContents that this is attached to is cloned, give the new clone 351 // When the WebContents that this is attached to is cloned, give the new clone
285 // a TabHelper and copy state over. 352 // a TabHelper and copy state over.
286 CreateForWebContents(new_web_contents); 353 CreateForWebContents(new_web_contents);
287 TabHelper* new_helper = FromWebContents(new_web_contents); 354 TabHelper* new_helper = FromWebContents(new_web_contents);
288 355
289 new_helper->SetExtensionApp(extension_app()); 356 new_helper->SetExtensionApp(extension_app());
290 new_helper->extension_app_icon_ = extension_app_icon_; 357 new_helper->extension_app_icon_ = extension_app_icon_;
291 } 358 }
(...skipping 10 matching lines...) Expand all
302 return; 369 return;
303 370
304 switch (pending_web_app_action_) { 371 switch (pending_web_app_action_) {
305 case CREATE_SHORTCUT: { 372 case CREATE_SHORTCUT: {
306 chrome::ShowCreateWebAppShortcutsDialog( 373 chrome::ShowCreateWebAppShortcutsDialog(
307 web_contents()->GetView()->GetTopLevelNativeWindow(), 374 web_contents()->GetView()->GetTopLevelNativeWindow(),
308 web_contents()); 375 web_contents());
309 break; 376 break;
310 } 377 }
311 case CREATE_HOSTED_APP: { 378 case CREATE_HOSTED_APP: {
312 CreateHostedApp(info); 379 CreateHostedApp();
313 break; 380 break;
314 } 381 }
315 case UPDATE_SHORTCUT: { 382 case UPDATE_SHORTCUT: {
316 web_app::UpdateShortcutForTabContents(web_contents()); 383 web_app::UpdateShortcutForTabContents(web_contents());
317 break; 384 break;
318 } 385 }
319 default: 386 default:
320 NOTREACHED(); 387 NOTREACHED();
321 break; 388 break;
322 } 389 }
323 390
324 // The hosted app action will be cleared once the installation completes or 391 // The hosted app action will be cleared once the installation completes or
325 // fails. 392 // fails.
326 if (pending_web_app_action_ != CREATE_HOSTED_APP) 393 if (pending_web_app_action_ != CREATE_HOSTED_APP)
327 pending_web_app_action_ = NONE; 394 pending_web_app_action_ = NONE;
328 #endif 395 #endif
329 } 396 }
330 397
331 void TabHelper::CreateHostedApp(const WebApplicationInfo& info) {
332 ShellIntegration::ShortcutInfo shortcut_info;
333 web_app::GetShortcutInfoForTab(web_contents(), &shortcut_info);
334 WebApplicationInfo web_app_info;
335
336 web_app_info.is_bookmark_app = true;
337 web_app_info.app_url = shortcut_info.url;
338 web_app_info.title = shortcut_info.title;
339 web_app_info.urls.push_back(web_app_info.app_url);
340
341 // TODO(calamity): this should attempt to download the best icon that it can
342 // from |info.icons| rather than just using the favicon as it scales up badly.
343 // Fix this once |info.icons| gets populated commonly.
344
345 // Get the smallest icon in the icon family (should have only 1).
346 const gfx::Image* icon = shortcut_info.favicon.GetBest(0, 0);
347 SkBitmap bitmap = icon ? icon->AsBitmap() : SkBitmap();
348
349 if (!icon->IsEmpty()) {
350 WebApplicationInfo::IconInfo icon_info;
351 icon_info.data = bitmap;
352 icon_info.width = icon_info.data.width();
353 icon_info.height = icon_info.data.height();
354 web_app_info.icons.push_back(icon_info);
355 }
356
357 ExtensionService* service = profile_->GetExtensionService();
358 scoped_refptr<extensions::CrxInstaller> installer(
359 extensions::CrxInstaller::CreateSilent(service));
360 installer->set_error_on_unsupported_requirements(true);
361 installer->InstallWebApp(web_app_info);
362 }
363
364 void TabHelper::OnInlineWebstoreInstall( 398 void TabHelper::OnInlineWebstoreInstall(
365 int install_id, 399 int install_id,
366 int return_route_id, 400 int return_route_id,
367 const std::string& webstore_item_id, 401 const std::string& webstore_item_id,
368 const GURL& requestor_url) { 402 const GURL& requestor_url) {
369 WebstoreStandaloneInstaller::Callback callback = 403 WebstoreStandaloneInstaller::Callback callback =
370 base::Bind(&TabHelper::OnInlineInstallComplete, base::Unretained(this), 404 base::Bind(&TabHelper::OnInlineInstallComplete, base::Unretained(this),
371 install_id, return_route_id); 405 install_id, return_route_id);
372 scoped_refptr<WebstoreInlineInstaller> installer( 406 scoped_refptr<WebstoreInlineInstaller> installer(
373 webstore_inline_installer_factory_->CreateInstaller( 407 webstore_inline_installer_factory_->CreateInstaller(
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 } 633 }
600 } 634 }
601 635
602 void TabHelper::SetTabId(RenderViewHost* render_view_host) { 636 void TabHelper::SetTabId(RenderViewHost* render_view_host) {
603 render_view_host->Send( 637 render_view_host->Send(
604 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), 638 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(),
605 SessionID::IdForTab(web_contents()))); 639 SessionID::IdForTab(web_contents())));
606 } 640 }
607 641
608 } // namespace extensions 642 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/tab_helper.h ('k') | chrome/browser/favicon/favicon_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698