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

Side by Side Diff: chrome/browser/ui/search_engines/search_engine_tab_helper.cc

Issue 10963042: Switch SearchEngineTabHelper to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: on the road again Created 8 years, 3 months 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 | Annotate | Revision Log
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/ui/search_engines/search_engine_tab_helper.h" 5 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/search_engines/template_url.h" 8 #include "chrome/browser/search_engines/template_url.h"
9 #include "chrome/browser/search_engines/template_url_fetcher.h" 9 #include "chrome/browser/search_engines/template_url_fetcher.h"
10 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" 10 #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
11 #include "chrome/browser/search_engines/template_url_service.h" 11 #include "chrome/browser/search_engines/template_url_service.h"
12 #include "chrome/browser/search_engines/template_url_service_factory.h" 12 #include "chrome/browser/search_engines/template_url_service_factory.h"
13 #include "chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h" 13 #include "chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h"
14 #include "chrome/common/render_messages.h" 14 #include "chrome/common/render_messages.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "content/public/browser/favicon_status.h" 16 #include "content/public/browser/favicon_status.h"
17 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
18 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "content/public/common/frame_navigate_params.h" 20 #include "content/public/common/frame_navigate_params.h"
21 21
22 using content::NavigationController; 22 using content::NavigationController;
23 using content::NavigationEntry; 23 using content::NavigationEntry;
24 using content::WebContents; 24 using content::WebContents;
25 25
26 int SearchEngineTabHelper::kUserDataKey;
27
26 namespace { 28 namespace {
27 29
28 // Returns true if the entry's transition type is FORM_SUBMIT. 30 // Returns true if the entry's transition type is FORM_SUBMIT.
29 bool IsFormSubmit(const NavigationEntry* entry) { 31 bool IsFormSubmit(const NavigationEntry* entry) {
30 return (content::PageTransitionStripQualifier(entry->GetTransitionType()) == 32 return (content::PageTransitionStripQualifier(entry->GetTransitionType()) ==
31 content::PAGE_TRANSITION_FORM_SUBMIT); 33 content::PAGE_TRANSITION_FORM_SUBMIT);
32 } 34 }
33 35
34 string16 GenerateKeywordFromNavigationEntry(const NavigationEntry* entry) { 36 string16 GenerateKeywordFromNavigationEntry(const NavigationEntry* entry) {
35 // Don't autogenerate keywords for pages that are the result of form 37 // Don't autogenerate keywords for pages that are the result of form
(...skipping 17 matching lines...) Expand all
53 // elements and update AutocompletePopup to look for keywords using the path. 55 // elements and update AutocompletePopup to look for keywords using the path.
54 // See http://b/issue?id=863583. 56 // See http://b/issue?id=863583.
55 if (!url.SchemeIs(chrome::kHttpScheme) || (url.path().length() > 1)) 57 if (!url.SchemeIs(chrome::kHttpScheme) || (url.path().length() > 1))
56 return string16(); 58 return string16();
57 59
58 return TemplateURLService::GenerateKeyword(url); 60 return TemplateURLService::GenerateKeyword(url);
59 } 61 }
60 62
61 } // namespace 63 } // namespace
62 64
63 SearchEngineTabHelper::SearchEngineTabHelper(WebContents* web_contents)
64 : content::WebContentsObserver(web_contents) {
65 DCHECK(web_contents);
66 }
67
68 SearchEngineTabHelper::~SearchEngineTabHelper() { 65 SearchEngineTabHelper::~SearchEngineTabHelper() {
69 } 66 }
70 67
71 void SearchEngineTabHelper::DidNavigateMainFrame( 68 void SearchEngineTabHelper::DidNavigateMainFrame(
72 const content::LoadCommittedDetails& /*details*/, 69 const content::LoadCommittedDetails& /*details*/,
73 const content::FrameNavigateParams& params) { 70 const content::FrameNavigateParams& params) {
74 GenerateKeywordIfNecessary(params); 71 GenerateKeywordIfNecessary(params);
75 } 72 }
76 73
77 bool SearchEngineTabHelper::OnMessageReceived(const IPC::Message& message) { 74 bool SearchEngineTabHelper::OnMessageReceived(const IPC::Message& message) {
78 bool handled = true; 75 bool handled = true;
79 IPC_BEGIN_MESSAGE_MAP(SearchEngineTabHelper, message) 76 IPC_BEGIN_MESSAGE_MAP(SearchEngineTabHelper, message)
80 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageHasOSDD, OnPageHasOSDD) 77 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageHasOSDD, OnPageHasOSDD)
81 IPC_MESSAGE_UNHANDLED(handled = false) 78 IPC_MESSAGE_UNHANDLED(handled = false)
82 IPC_END_MESSAGE_MAP() 79 IPC_END_MESSAGE_MAP()
83 80
84 return handled; 81 return handled;
85 } 82 }
86 83
84 SearchEngineTabHelper::SearchEngineTabHelper(WebContents* web_contents)
85 : content::WebContentsObserver(web_contents) {
86 DCHECK(web_contents);
87 }
88
87 void SearchEngineTabHelper::OnPageHasOSDD( 89 void SearchEngineTabHelper::OnPageHasOSDD(
88 int32 page_id, 90 int32 page_id,
89 const GURL& doc_url, 91 const GURL& doc_url,
90 const search_provider::OSDDType& msg_provider_type) { 92 const search_provider::OSDDType& msg_provider_type) {
91 // Checks to see if we should generate a keyword based on the OSDD, and if 93 // Checks to see if we should generate a keyword based on the OSDD, and if
92 // necessary uses TemplateURLFetcher to download the OSDD and create a 94 // necessary uses TemplateURLFetcher to download the OSDD and create a
93 // keyword. 95 // keyword.
94 96
95 // Make sure page_id is the current page and other basic checks. 97 // Make sure page_id is the current page and other basic checks.
96 DCHECK(doc_url.is_valid()); 98 DCHECK(doc_url.is_valid());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // the favicon url wasn't obtained before the load started. This assumes the 194 // the favicon url wasn't obtained before the load started. This assumes the
193 // latter. 195 // latter.
194 // TODO(sky): Need a way to set the favicon that doesn't involve generating 196 // TODO(sky): Need a way to set the favicon that doesn't involve generating
195 // its url. 197 // its url.
196 data.favicon_url = current_favicon.is_valid() ? 198 data.favicon_url = current_favicon.is_valid() ?
197 current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url); 199 current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url);
198 data.safe_for_autoreplace = true; 200 data.safe_for_autoreplace = true;
199 data.input_encodings.push_back(params.searchable_form_encoding); 201 data.input_encodings.push_back(params.searchable_form_encoding);
200 url_service->Add(new TemplateURL(profile, data)); 202 url_service->Add(new TemplateURL(profile, data));
201 } 203 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search_engines/search_engine_tab_helper.h ('k') | chrome/browser/ui/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698