• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_SEARCH_ENGINES_SEARCH_ENGINE_TAB_HELPER_H_
6 #define CHROME_BROWSER_UI_SEARCH_ENGINES_SEARCH_ENGINE_TAB_HELPER_H_
7 
8 #include "base/memory/weak_ptr.h"
9 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
10 #include "chrome/browser/ui/find_bar/find_notification_details.h"
11 #include "chrome/common/search_provider.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/browser/web_contents_user_data.h"
14 
15 class SearchEngineTabHelperDelegate;
16 class TemplateURL;
17 
18 // Per-tab search engine manager. Handles dealing search engine processing
19 // functionality.
20 class SearchEngineTabHelper
21     : public content::WebContentsObserver,
22       public content::WebContentsUserData<SearchEngineTabHelper> {
23  public:
24   virtual ~SearchEngineTabHelper();
25 
delegate()26   SearchEngineTabHelperDelegate* delegate() const { return delegate_; }
set_delegate(SearchEngineTabHelperDelegate * d)27   void set_delegate(SearchEngineTabHelperDelegate* d) { delegate_ = d; }
28 
29   // content::WebContentsObserver overrides.
30   virtual void DidNavigateMainFrame(
31       const content::LoadCommittedDetails& details,
32       const content::FrameNavigateParams& params) OVERRIDE;
33   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
34 
35  private:
36   explicit SearchEngineTabHelper(content::WebContents* web_contents);
37   friend class content::WebContentsUserData<SearchEngineTabHelper>;
38 
39   // Handles when a page specifies an OSDD (OpenSearch Description Document).
40   void OnPageHasOSDD(const GURL& page_url,
41                      const GURL& osdd_url,
42                      const search_provider::OSDDType& msg_provider_type);
43 
44   // Handles when an OSDD is downloaded.
45   void OnDownloadedOSDD(scoped_ptr<TemplateURL> template_url);
46 
47   // If params has a searchable form, this tries to create a new keyword.
48   void GenerateKeywordIfNecessary(
49       const content::FrameNavigateParams& params);
50 
51   // Delegate for notifying our owner about stuff. Not owned by us.
52   SearchEngineTabHelperDelegate* delegate_;
53 
54   base::WeakPtrFactory<SearchEngineTabHelper> weak_ptr_factory_;
55 
56   DISALLOW_COPY_AND_ASSIGN(SearchEngineTabHelper);
57 };
58 
59 #endif  // CHROME_BROWSER_UI_SEARCH_ENGINES_SEARCH_ENGINE_TAB_HELPER_H_
60