• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/android/new_tab_page_url_handler.h"
6 
7 #include <string>
8 
9 #include "base/strings/string_util.h"
10 #include "chrome/common/url_constants.h"
11 #include "content/public/common/url_constants.h"
12 #include "url/gurl.h"
13 
14 namespace {
15 const char kLegacyBookmarksFragment[] = "bookmarks";
16 const char kLegacyOpenTabsFragment[] = "open_tabs";
17 const char kLegacyRecentTabsHost[] = "recent_tabs";
18 }
19 
20 namespace chrome {
21 namespace android {
22 
HandleAndroidNewTabURL(GURL * url,content::BrowserContext * browser_context)23 bool HandleAndroidNewTabURL(GURL* url,
24                             content::BrowserContext* browser_context) {
25   if (url->SchemeIs(content::kChromeUIScheme) &&
26       url->host() == chrome::kChromeUINewTabHost) {
27     std::string ref = url->ref();
28     if (StartsWithASCII(ref, kLegacyBookmarksFragment, true)) {
29       *url = GURL(chrome::kChromeUINativeBookmarksURL);
30     } else if (ref == kLegacyOpenTabsFragment) {
31       *url = GURL(chrome::kChromeUINativeRecentTabsURL);
32     } else {
33       *url = GURL(chrome::kChromeUINativeNewTabURL);
34     }
35     return true;
36   }
37 
38   if (url->SchemeIs(chrome::kChromeNativeScheme) &&
39       url->host() == kLegacyRecentTabsHost) {
40     *url = GURL(chrome::kChromeUINativeRecentTabsURL);
41     return true;
42   }
43 
44   return false;
45 }
46 
47 }  // namespace android
48 }  // namespace chrome
49