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

Side by Side Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 1489873004: When an offline page is saved to homescreen, use the online URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds docs for the new convenience method. Created 5 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/android/webapps/add_to_homescreen_data_fetcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/webapps/add_to_homescreen_data_fetcher.h" 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/task/cancelable_task_tracker.h" 10 #include "base/task/cancelable_task_tracker.h"
11 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
11 #include "chrome/browser/android/shortcut_helper.h" 12 #include "chrome/browser/android/shortcut_helper.h"
12 #include "chrome/browser/favicon/favicon_service_factory.h" 13 #include "chrome/browser/favicon/favicon_service_factory.h"
13 #include "chrome/browser/manifest/manifest_icon_downloader.h" 14 #include "chrome/browser/manifest/manifest_icon_downloader.h"
14 #include "chrome/browser/manifest/manifest_icon_selector.h" 15 #include "chrome/browser/manifest/manifest_icon_selector.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/render_messages.h" 18 #include "chrome/common/render_messages.h"
18 #include "chrome/common/web_application_info.h" 19 #include "chrome/common/web_application_info.h"
19 #include "components/dom_distiller/core/url_utils.h" 20 #include "components/dom_distiller/core/url_utils.h"
20 #include "components/favicon/core/favicon_service.h" 21 #include "components/favicon/core/favicon_service.h"
22 #include "components/offline_pages/offline_page_feature.h"
23 #include "components/offline_pages/offline_page_item.h"
24 #include "components/offline_pages/offline_page_model.h"
21 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
23 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_observer.h" 28 #include "content/public/browser/web_contents_observer.h"
25 #include "content/public/common/frame_navigate_params.h" 29 #include "content/public/common/frame_navigate_params.h"
26 #include "content/public/common/manifest.h" 30 #include "content/public/common/manifest.h"
27 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 31 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
28 #include "ui/gfx/codec/png_codec.h" 32 #include "ui/gfx/codec/png_codec.h"
29 #include "ui/gfx/favicon_size.h" 33 #include "ui/gfx/favicon_size.h"
30 #include "ui/gfx/screen.h" 34 #include "ui/gfx/screen.h"
31 #include "url/gurl.h" 35 #include "url/gurl.h"
32 36
33 using content::Manifest; 37 using content::Manifest;
34 38
35 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( 39 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
36 content::WebContents* web_contents, 40 content::WebContents* web_contents,
37 int ideal_icon_size_in_dp, 41 int ideal_icon_size_in_dp,
38 int minimum_icon_size_in_dp, 42 int minimum_icon_size_in_dp,
39 int ideal_splash_image_size_in_dp, 43 int ideal_splash_image_size_in_dp,
40 int minimum_splash_image_size_in_dp, 44 int minimum_splash_image_size_in_dp,
41 Observer* observer) 45 Observer* observer)
42 : WebContentsObserver(web_contents), 46 : WebContentsObserver(web_contents),
43 weak_observer_(observer), 47 weak_observer_(observer),
44 is_waiting_for_web_application_info_(false), 48 is_waiting_for_web_application_info_(false),
45 is_icon_saved_(false), 49 is_icon_saved_(false),
46 is_ready_(false), 50 is_ready_(false),
47 icon_timeout_timer_(false, false), 51 icon_timeout_timer_(false, false),
48 shortcut_info_(dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl( 52 shortcut_info_(GetShortcutUrl(web_contents->GetURL())),
49 web_contents->GetURL())),
50 ideal_icon_size_in_dp_(ideal_icon_size_in_dp), 53 ideal_icon_size_in_dp_(ideal_icon_size_in_dp),
51 minimum_icon_size_in_dp_(minimum_icon_size_in_dp), 54 minimum_icon_size_in_dp_(minimum_icon_size_in_dp),
52 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp), 55 ideal_splash_image_size_in_dp_(ideal_splash_image_size_in_dp),
53 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) { 56 minimum_splash_image_size_in_dp_(minimum_splash_image_size_in_dp) {
54 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); 57 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp);
55 DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp); 58 DCHECK(minimum_splash_image_size_in_dp <= ideal_splash_image_size_in_dp);
56 59
57 // Send a message to the renderer to retrieve information about the page. 60 // Send a message to the renderer to retrieve information about the page.
58 is_waiting_for_web_application_info_ = true; 61 is_waiting_for_web_application_info_ = true;
59 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 62 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
265 if (!web_contents() || !weak_observer_ || is_icon_saved_) 268 if (!web_contents() || !weak_observer_ || is_icon_saved_)
266 return; 269 return;
267 270
268 is_icon_saved_ = true; 271 is_icon_saved_ = true;
269 shortcut_icon_ = bitmap; 272 shortcut_icon_ = bitmap;
270 shortcut_info_.is_icon_generated = is_generated; 273 shortcut_info_.is_icon_generated = is_generated;
271 is_ready_ = true; 274 is_ready_ = true;
272 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); 275 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_);
273 } 276 }
277
278 GURL AddToHomescreenDataFetcher::GetShortcutUrl(const GURL& actual_url) {
279 GURL shortcut_url =
280 dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url);
281
282 if (!offline_pages::IsOfflinePagesEnabled())
283 return shortcut_url;
284
285 Profile* profile =
286 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
287
288 offline_pages::OfflinePageModel* offline_page_model =
289 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile);
290 const offline_pages::OfflinePageItem* offline_page =
291 offline_page_model->GetPageByOfflineURL(shortcut_url);
292 if (!offline_page)
293 return shortcut_url;
294
295 return offline_page->url;
296 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698