| 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 namespace content { |
| 30 |
| 31 // This enum must be kept in sync with ContentViewClient.java |
| 32 enum ContentViewClientError { |
| 33 // Success |
| 34 CONTENT_VIEW_CLIENT_ERROR_OK = 0, |
| 35 // Generic error |
| 36 CONTENT_VIEW_CLIENT_ERROR_UNKNOWN = -1, |
| 37 // Server or proxy hostname lookup failed |
| 38 CONTENT_VIEW_CLIENT_ERROR_HOST_LOOKUP = -2, |
| 39 // Unsupported authentication scheme (not basic or digest) |
| 40 CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_AUTH_SCHEME = -3, |
| 41 // User authentication failed on server |
| 42 CONTENT_VIEW_CLIENT_ERROR_AUTHENTICATION = -4, |
| 43 // User authentication failed on proxy |
| 44 CONTENT_VIEW_CLIENT_ERROR_PROXY_AUTHENTICATION = -5, |
| 45 // Failed to connect to the server |
| 46 CONTENT_VIEW_CLIENT_ERROR_CONNECT = -6, |
| 47 // Failed to read or write to the server |
| 48 CONTENT_VIEW_CLIENT_ERROR_IO = -7, |
| 49 // Connection timed out |
| 50 CONTENT_VIEW_CLIENT_ERROR_TIMEOUT = -8, |
| 51 // Too many redirects |
| 52 CONTENT_VIEW_CLIENT_ERROR_REDIRECT_LOOP = -9, |
| 53 // Unsupported URI scheme |
| 54 CONTENT_VIEW_CLIENT_ERROR_UNSUPPORTED_SCHEME = -10, |
| 55 // Failed to perform SSL handshake |
| 56 CONTENT_VIEW_CLIENT_ERROR_FAILED_SSL_HANDSHAKE = -11, |
| 57 // Malformed URL |
| 58 CONTENT_VIEW_CLIENT_ERROR_BAD_URL = -12, |
| 59 // Generic file error |
| 60 CONTENT_VIEW_CLIENT_ERROR_FILE = -13, |
| 61 // File not found |
| 62 CONTENT_VIEW_CLIENT_ERROR_FILE_NOT_FOUND = -14, |
| 63 // Too many requests during this load |
| 64 CONTENT_VIEW_CLIENT_ERROR_TOO_MANY_REQUESTS = -15, |
| 65 }; |
| 66 |
| 67 // Native mirror of ContentViewClient.java. Uses as a client of |
| 68 // ContentView, the main FrameLayout on Android. |
| 69 class ContentViewClient : public 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(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 JavaScriptDialogCreator* javascript_dialog_creator); |
| 97 |
| 98 bool OnJSModalDialog(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 WebContents* OpenURLFromTab( |
| 106 WebContents* source, |
| 107 const OpenURLParams& params) OVERRIDE; |
| 108 virtual bool ShouldIgnoreNavigation( |
| 109 WebContents* source, |
| 110 const GURL& url, |
| 111 const Referrer& referrer, |
| 112 WindowOpenDisposition disposition, |
| 113 PageTransition transition_type) OVERRIDE; |
| 114 virtual void NavigationStateChanged(const WebContents* source, |
| 115 unsigned changed_flags) OVERRIDE; |
| 116 virtual void AddNewContents(WebContents* source, |
| 117 WebContents* new_contents, |
| 118 WindowOpenDisposition disposition, |
| 119 const gfx::Rect& initial_pos, |
| 120 bool user_gesture) OVERRIDE; |
| 121 virtual void ActivateContents(WebContents* contents) OVERRIDE; |
| 122 virtual void DeactivateContents(WebContents* contents) OVERRIDE; |
| 123 virtual void LoadingStateChanged(WebContents* source) OVERRIDE; |
| 124 virtual void LoadProgressChanged(double load_progress) OVERRIDE; |
| 125 virtual void CloseContents(WebContents* source) OVERRIDE; |
| 126 virtual void MoveContents(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(WebContents* source, bool starred); |
| 131 virtual void UpdateTargetURL(WebContents* source, |
| 132 int32 page_id, |
| 133 const GURL& url) OVERRIDE; |
| 134 virtual bool CanDownload(RenderViewHost* source, |
| 135 int request_id, |
| 136 const std::string& request_method) OVERRIDE; |
| 137 virtual void OnStartDownload(WebContents* source, |
| 138 DownloadItem* download) OVERRIDE; |
| 139 virtual void FindReply(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( |
| 150 const NativeWebKeyboardEvent& event) OVERRIDE; |
| 151 virtual JavaScriptDialogCreator* GetJavaScriptDialogCreator() OVERRIDE; |
| 152 virtual void RunFileChooser( |
| 153 WebContents* tab, |
| 154 const FileChooserParams& params) OVERRIDE; |
| 155 virtual bool TakeFocus(bool reverse) OVERRIDE; |
| 156 |
| 157 virtual ~ContentViewClient(); |
| 158 |
| 159 private: |
| 160 // Get the closest ContentViewClient match to the given Chrome error code. |
| 161 static ContentViewClientError ToContentViewClientError(int net_error); |
| 162 |
| 163 // We use this to keep track of whether the navigation we get in |
| 164 // ShouldIgnoreNavigation has been initiated by the ContentView or not. We |
| 165 // need the GURL, because the active navigation entry doesn't change on |
| 166 // redirects. |
| 167 GURL last_requested_navigation_url_; |
| 168 |
| 169 // We depend on ContentView.java to hold a ref to the client object. If we |
| 170 // were to hold a hard ref from native we could end up with a cyclic |
| 171 // ownership leak (the GC can't collect cycles if part of the cycle is caused |
| 172 // by native). |
| 173 JavaObjectWeakGlobalRef weak_java_client_; |
| 174 |
| 175 // Used to process find replies. Owned by the ContentView. The ContentView |
| 176 // NULLs this pointer when the FindHelper goes away. |
| 177 FindHelper* find_helper_; |
| 178 |
| 179 // The object responsible for creating JavaScript dialogs. |
| 180 JavaScriptDialogCreator* javascript_dialog_creator_; |
| 181 }; |
| 182 |
| 183 bool RegisterContentViewClient(JNIEnv* env); |
| 184 |
| 185 } // namespace content |
| 186 |
| 187 #endif // CONTENT_BROWSER_ANDROID_CONTENT_VIEW_CLIENT_H_ |
| OLD | NEW |