| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright (c) 2010 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 CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | 
|  | 6 #define CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | 
|  | 7 #pragma once | 
|  | 8 | 
|  | 9 #include "base/android/jni_helper.h" | 
|  | 10 #include "base/compiler_specific.h" | 
|  | 11 #include "content/public/browser/native_web_keyboard_event.h" | 
|  | 12 #include "content/public/browser/web_contents_delegate.h" | 
|  | 13 #include "content/public/common/javascript_message_type.h" | 
|  | 14 #include "content/public/common/referrer.h" | 
|  | 15 #include "googleurl/src/gurl.h" | 
|  | 16 #include "net/base/net_errors.h" | 
|  | 17 | 
|  | 18 class FindHelper; | 
|  | 19 | 
|  | 20 namespace content { | 
|  | 21 class DownloadItem; | 
|  | 22 struct FindMatchRect; | 
|  | 23 class JavaScriptDialogCreator; | 
|  | 24 class NativeWebKeyboardEvent; | 
|  | 25 class RenderViewHost; | 
|  | 26 class WebContents; | 
|  | 27 } | 
|  | 28 | 
|  | 29 // This enum must be kept in sync with ContentViewClient.java | 
|  | 30 enum ContentViewClientError { | 
|  | 31   // Success | 
|  | 32   CONTENT_VIEW_CLIENT_ERROR_OK = 0, | 
|  | 33   // Generic error | 
|  | 34   CONTENT_VIEW_CLIENT_ERROR_UNKNOWN = -1, | 
|  | 35   // Server or proxy hostname lookup failed | 
|  | 36   CONTENT_VIEW_CLIENT_ERROR_HOST_LOOKUP = -2, | 
|  | 37   // Unsupported authentication scheme (not basic or digest) | 
|  | 38   CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_AUTH_SCHEME = -3, | 
|  | 39   // User authentication failed on server | 
|  | 40   CONTENT_VIEW_CLIENT_ERROR_AUTHENTICATION = -4, | 
|  | 41   // User authentication failed on proxy | 
|  | 42   CONTENT_VIEW_CLIENT_ERROR_PROXY_AUTHENTICATION = -5, | 
|  | 43   // Failed to connect to the server | 
|  | 44   CONTENT_VIEW_CLIENT_ERROR_CONNECT = -6, | 
|  | 45   // Failed to read or write to the server | 
|  | 46   CONTENT_VIEW_CLIENT_ERROR_IO = -7, | 
|  | 47   // Connection timed out | 
|  | 48   CONTENT_VIEW_CLIENT_ERROR_TIMEOUT = -8, | 
|  | 49   // Too many redirects | 
|  | 50   CONTENT_VIEW_CLIENT_ERROR_REDIRECT_LOOP = -9, | 
|  | 51   // Unsupported URI scheme | 
|  | 52   CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_SCHEME = -10, | 
|  | 53   // Failed to perform SSL handshake | 
|  | 54   CONTENT_VIEW_CLIENT_ERROR_FAILED_SSL_HANDSHAKE = -11, | 
|  | 55   // Malformed URL | 
|  | 56   CONTENT_VIEW_CLIENT_ERROR_BAD_URL = -12, | 
|  | 57   // Generic file error | 
|  | 58   CONTENT_VIEW_CLIENT_ERROR_FILE = -13, | 
|  | 59   // File not found | 
|  | 60   CONTENT_VIEW_CLIENT_ERROR_FILE_NOT_FOUND = -14, | 
|  | 61   // Too many requests during this load | 
|  | 62   CONTENT_VIEW_CLIENT_ERROR_TOO_MANY_REQUESTS = -15, | 
|  | 63 }; | 
|  | 64 | 
|  | 65 namespace content { | 
|  | 66 | 
|  | 67 // Native mirror of ContentViewClient.java.  Uses as a client of | 
|  | 68 // ContentView, the main FrameLayout on Android. | 
|  | 69 class ContentViewClient : public content::WebContentsDelegate { | 
|  | 70  public: | 
|  | 71   ContentViewClient(JNIEnv* env, jobject obj); | 
|  | 72 | 
|  | 73   static ContentViewClient* CreateNativeContentViewClient(JNIEnv* env, | 
|  | 74                                                           jobject obj); | 
|  | 75 | 
|  | 76   // Called by ContentView: | 
|  | 77   void OnInternalPageLoadRequest(content::WebContents* source, | 
|  | 78                                  const GURL& url); | 
|  | 79   void OnPageStarted(const GURL& url); | 
|  | 80   void OnPageFinished(const GURL& url); | 
|  | 81   void OnLoadStarted(); | 
|  | 82   void OnLoadStopped(); | 
|  | 83   void OnReceivedError(int error_code, | 
|  | 84                        const string16& description, | 
|  | 85                        const GURL& url); | 
|  | 86   void OnReceivedHttpAuthRequest(jobject auth_handler, | 
|  | 87                                  const string16& host, | 
|  | 88                                  const string16& realm); | 
|  | 89   void OnDidCommitMainFrame(const GURL& url, | 
|  | 90                             const GURL& base_url); | 
|  | 91   void OnInterstitialShown(); | 
|  | 92   void OnInterstitialHidden(); | 
|  | 93 | 
|  | 94   void SetFindHelper(FindHelper* find_helper); | 
|  | 95   void SetJavaScriptDialogCreator( | 
|  | 96       content::JavaScriptDialogCreator* javascript_dialog_creator); | 
|  | 97 | 
|  | 98   bool OnJSModalDialog(content::JavaScriptMessageType type, | 
|  | 99                        bool is_before_unload_dialog, | 
|  | 100                        const GURL& url, | 
|  | 101                        const string16& message, | 
|  | 102                        const string16& default_value); | 
|  | 103 | 
|  | 104   // Overridden from WebContentsDelegate: | 
|  | 105   virtual content::WebContents* OpenURLFromTab( | 
|  | 106       content::WebContents* source, | 
|  | 107       const content::OpenURLParams& params) OVERRIDE; | 
|  | 108   virtual bool ShouldIgnoreNavigation( | 
|  | 109       content::WebContents* source, | 
|  | 110       const GURL& url, | 
|  | 111       const content::Referrer& referrer, | 
|  | 112       WindowOpenDisposition disposition, | 
|  | 113       content::PageTransition transition_type) OVERRIDE; | 
|  | 114   virtual void NavigationStateChanged(const content::WebContents* source, | 
|  | 115                                       unsigned changed_flags) OVERRIDE; | 
|  | 116   virtual void AddNewContents(content::WebContents* source, | 
|  | 117                               content::WebContents* new_contents, | 
|  | 118                               WindowOpenDisposition disposition, | 
|  | 119                               const gfx::Rect& initial_pos, | 
|  | 120                               bool user_gesture) OVERRIDE; | 
|  | 121   virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | 
|  | 122   virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; | 
|  | 123   virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | 
|  | 124   virtual void LoadProgressChanged(double load_progress) OVERRIDE; | 
|  | 125   virtual void CloseContents(content::WebContents* source) OVERRIDE; | 
|  | 126   virtual void MoveContents(content::WebContents* source, | 
|  | 127                             const gfx::Rect& pos) OVERRIDE; | 
|  | 128   // TODO(merge): WARNING! method no longer available on the base class. | 
|  | 129   // See http://b/issue?id=5862108 | 
|  | 130   virtual void URLStarredChanged(content::WebContents* source, bool starred); | 
|  | 131   virtual void UpdateTargetURL(content::WebContents* source, | 
|  | 132                                int32 page_id, | 
|  | 133                                const GURL& url) OVERRIDE; | 
|  | 134   virtual bool CanDownload(content::RenderViewHost* source, | 
|  | 135                            int request_id, | 
|  | 136                            const std::string& request_method) OVERRIDE; | 
|  | 137   virtual void OnStartDownload(content::WebContents* source, | 
|  | 138                                content::DownloadItem* download) OVERRIDE; | 
|  | 139   virtual void FindReply(content::WebContents* tab, | 
|  | 140                          int request_id, | 
|  | 141                          int number_of_matches, | 
|  | 142                          const gfx::Rect& selection_rect, | 
|  | 143                          int active_match_ordinal, | 
|  | 144                          bool final_update) OVERRIDE; | 
|  | 145   virtual void OnReceiveFindMatchRects(int version, | 
|  | 146       const std::vector<FindMatchRect>& rects, | 
|  | 147       const FindMatchRect& active_rect) OVERRIDE; | 
|  | 148   virtual bool ShouldOverrideLoading(const GURL& url) OVERRIDE; | 
|  | 149   virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) OVERRIDE
     ; | 
|  | 150   virtual content::JavaScriptDialogCreator* GetJavaScriptDialogCreator() OVERRID
     E; | 
|  | 151   virtual void RunFileChooser(content::WebContents* tab, | 
|  | 152                               const content::FileChooserParams& params) OVERRIDE
     ; | 
|  | 153   virtual bool TakeFocus(bool reverse) OVERRIDE; | 
|  | 154 | 
|  | 155   virtual ~ContentViewClient(); | 
|  | 156 | 
|  | 157  private: | 
|  | 158   // Get the closest ContentViewClient match to the given Chrome error code. | 
|  | 159   static ContentViewClientError ToContentViewClientError(int net_error); | 
|  | 160 | 
|  | 161   // We use this to keep track of whether the navigation we get in | 
|  | 162   // ShouldIgnoreNavigation has been initiated by the ContentView or not.  We | 
|  | 163   // need the GURL, because the active navigation entry doesn't change on | 
|  | 164   // redirects. | 
|  | 165   GURL last_requested_navigation_url_; | 
|  | 166 | 
|  | 167   // We depend on ContentView.java to hold a ref to the client object. If we | 
|  | 168   // were to hold a hard ref from native we could end up with a cyclic | 
|  | 169   // ownership leak (the GC can't collect cycles if part of the cycle is caused | 
|  | 170   // by native). | 
|  | 171   JavaObjectWeakGlobalRef weak_java_client_; | 
|  | 172 | 
|  | 173   // Used to process find replies. Owned by the ContentView.  The ContentView | 
|  | 174   // NULLs this pointer when the FindHelper goes away. | 
|  | 175   FindHelper* find_helper_; | 
|  | 176 | 
|  | 177   // The object responsible for creating JavaScript dialogs. | 
|  | 178   content::JavaScriptDialogCreator* javascript_dialog_creator_; | 
|  | 179 }; | 
|  | 180 | 
|  | 181 bool RegisterContentViewClient(JNIEnv* env); | 
|  | 182 | 
|  | 183 }  // namespace content | 
|  | 184 | 
|  | 185 #endif  // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ | 
| OLD | NEW | 
|---|