| Index: content/browser/android/content_view_client.cc
|
| diff --git a/content/browser/android/content_view_client.cc b/content/browser/android/content_view_client.cc
|
| index d4e08fbc7260e000593302051a639d2086ec194b..b7d4a15f32156546e00ef4e348b39bb40311ebd3 100644
|
| --- a/content/browser/android/content_view_client.cc
|
| +++ b/content/browser/android/content_view_client.cc
|
| @@ -8,12 +8,9 @@
|
|
|
| #include "base/android/jni_android.h"
|
| #include "base/android/jni_string.h"
|
| -#include "content/browser/android/content_util.h"
|
| #include "content/browser/android/content_view_core_impl.h"
|
| #include "content/browser/android/download_controller.h"
|
| -#include "content/browser/android/ime_utils.h"
|
| #include "content/browser/renderer_host/render_view_host_impl.h"
|
| -#include "content/common/find_match_rect_android.h"
|
| #include "content/public/browser/render_widget_host_view.h"
|
| #include "content/public/browser/download_item.h"
|
| #include "content/public/browser/invalidate_type.h"
|
| @@ -25,8 +22,6 @@
|
| #include "content/public/common/referrer.h"
|
| #include "jni/ContentViewClient_jni.h"
|
| #include "net/http/http_request_headers.h"
|
| -#include "ui/gfx/rect.h"
|
| -#include "webkit/glue/window_open_disposition.h"
|
|
|
| using base::android::AttachCurrentThread;
|
| using base::android::CheckException;
|
| @@ -40,10 +35,7 @@ using base::android::ScopedJavaLocalRef;
|
| namespace content {
|
|
|
| ContentViewClient::ContentViewClient(JNIEnv* env, jobject obj)
|
| - : weak_java_client_(env, obj),
|
| - find_helper_(NULL),
|
| - javascript_dialog_creator_(NULL),
|
| - load_progress_(0) {
|
| + : weak_java_client_(env, obj) {
|
| }
|
|
|
| ContentViewClient::~ContentViewClient() {
|
| @@ -58,42 +50,45 @@ ContentViewClient* ContentViewClient::CreateNativeContentViewClient(
|
|
|
| void ContentViewClient::OnInternalPageLoadRequest(
|
| WebContents* source, const GURL& url) {
|
| - last_requested_navigation_url_ = url;
|
| }
|
|
|
|
|
| void ContentViewClient::OnPageStarted(const GURL& url) {
|
| JNIEnv* env = AttachCurrentThread();
|
| + ScopedJavaLocalRef<jobject> obj = weak_java_client_.get(env);
|
| + if (obj.is_null())
|
| + return;
|
| ScopedJavaLocalRef<jstring> jstring_url =
|
| ConvertUTF8ToJavaString(env, url.spec());
|
| - Java_ContentViewClient_onPageStarted(env, weak_java_client_.get(env).obj(),
|
| - jstring_url.obj());
|
| + Java_ContentViewClient_onPageStarted(env, obj.obj(), jstring_url.obj());
|
| }
|
|
|
| void ContentViewClient::OnPageFinished(const GURL& url) {
|
| - if (url == last_requested_navigation_url_)
|
| - last_requested_navigation_url_ = GURL::EmptyGURL();
|
| -
|
| JNIEnv* env = AttachCurrentThread();
|
| + ScopedJavaLocalRef<jobject> obj = weak_java_client_.get(env);
|
| + if (obj.is_null())
|
| + return;
|
| ScopedJavaLocalRef<jstring> jstring_url =
|
| ConvertUTF8ToJavaString(env, url.spec());
|
|
|
| - Java_ContentViewClient_onPageFinished(env, weak_java_client_.get(env).obj(),
|
| - jstring_url.obj());
|
| + Java_ContentViewClient_onPageFinished(env, obj.obj(), jstring_url.obj());
|
| CheckException(env);
|
| }
|
|
|
| void ContentViewClient::OnReceivedError(int error_code,
|
| - const string16& description,
|
| - const GURL& url) {
|
| + const string16& description,
|
| + const GURL& url) {
|
| JNIEnv* env = AttachCurrentThread();
|
| + ScopedJavaLocalRef<jobject> obj = weak_java_client_.get(env);
|
| + if (obj.is_null())
|
| + return;
|
| ScopedJavaLocalRef<jstring> jstring_error_description =
|
| ConvertUTF8ToJavaString(env, url.spec());
|
| ScopedJavaLocalRef<jstring> jstring_url =
|
| ConvertUTF8ToJavaString(env, url.spec());
|
|
|
| Java_ContentViewClient_onReceivedError(
|
| - env, weak_java_client_.get(env).obj(),
|
| + env, obj.obj(),
|
| ToContentViewClientError(error_code),
|
| jstring_error_description.obj(), jstring_url.obj());
|
| }
|
| @@ -101,35 +96,33 @@ void ContentViewClient::OnReceivedError(int error_code,
|
| void ContentViewClient::OnDidCommitMainFrame(const GURL& url,
|
| const GURL& base_url) {
|
| JNIEnv* env = AttachCurrentThread();
|
| + ScopedJavaLocalRef<jobject> obj = weak_java_client_.get(env);
|
| + if (obj.is_null())
|
| + return;
|
| ScopedJavaLocalRef<jstring> jstring_url =
|
| ConvertUTF8ToJavaString(env, url.spec());
|
| ScopedJavaLocalRef<jstring> jstring_base_url =
|
| ConvertUTF8ToJavaString(env, base_url.spec());
|
|
|
| Java_ContentViewClient_onMainFrameCommitted(
|
| - env, weak_java_client_.get(env).obj(),
|
| + env, obj.obj(),
|
| jstring_url.obj(), jstring_base_url.obj());
|
| }
|
|
|
| void ContentViewClient::OnInterstitialShown() {
|
| JNIEnv* env = AttachCurrentThread();
|
| - Java_ContentViewClient_onInterstitialShown(
|
| - env, weak_java_client_.get(env).obj());
|
| + ScopedJavaLocalRef<jobject> obj = weak_java_client_.get(env);
|
| + if (obj.is_null())
|
| + return;
|
| + Java_ContentViewClient_onInterstitialShown(env, obj.obj());
|
| }
|
|
|
| void ContentViewClient::OnInterstitialHidden() {
|
| JNIEnv* env = AttachCurrentThread();
|
| - Java_ContentViewClient_onInterstitialHidden(
|
| - env, weak_java_client_.get(env).obj());
|
| -}
|
| -
|
| -void ContentViewClient::SetFindHelper(FindHelper* find_helper) {
|
| - find_helper_ = find_helper;
|
| -}
|
| -
|
| -void ContentViewClient::SetJavaScriptDialogCreator(
|
| - JavaScriptDialogCreator* javascript_dialog_creator) {
|
| - javascript_dialog_creator_ = javascript_dialog_creator;
|
| + ScopedJavaLocalRef<jobject> obj = weak_java_client_.get(env);
|
| + if (obj.is_null())
|
| + return;
|
| + Java_ContentViewClient_onInterstitialHidden(env, obj.obj());
|
| }
|
|
|
| bool ContentViewClient::OnJSModalDialog(JavaScriptMessageType type,
|
| @@ -138,36 +131,36 @@ bool ContentViewClient::OnJSModalDialog(JavaScriptMessageType type,
|
| const string16& message,
|
| const string16& default_value) {
|
| JNIEnv* env = AttachCurrentThread();
|
| + ScopedJavaLocalRef<jobject> obj = weak_java_client_.get(env);
|
| + if (obj.is_null())
|
| + return false;
|
| ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString(env, url.spec()));
|
| ScopedJavaLocalRef<jstring> jmessage(ConvertUTF16ToJavaString(env, message));
|
|
|
| // Special case for beforeunload dialogs, as that isn't encoded in the
|
| // |type| of the dialog.
|
| if (is_before_unload_dialog) {
|
| - return Java_ContentViewClient_onJsBeforeUnload(env,
|
| - weak_java_client_.get(env).obj(),
|
| + return Java_ContentViewClient_onJsBeforeUnload(
|
| + env, obj.obj(),
|
| jurl.obj(),
|
| jmessage.obj());
|
| }
|
|
|
| switch (type) {
|
| case JAVASCRIPT_MESSAGE_TYPE_ALERT:
|
| - return Java_ContentViewClient_onJsAlert(env,
|
| - weak_java_client_.get(env).obj(),
|
| + return Java_ContentViewClient_onJsAlert(env, obj.obj(),
|
| jurl.obj(),
|
| jmessage.obj());
|
|
|
| case JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
|
| - return Java_ContentViewClient_onJsConfirm(env,
|
| - weak_java_client_.get(env).obj(),
|
| - jurl.obj(),
|
| - jmessage.obj());
|
| + return Java_ContentViewClient_onJsConfirm(env, obj.obj(),
|
| + jurl.obj(),
|
| + jmessage.obj());
|
|
|
| case JAVASCRIPT_MESSAGE_TYPE_PROMPT: {
|
| ScopedJavaLocalRef<jstring> jdefault_value(
|
| ConvertUTF16ToJavaString(env, default_value));
|
| - return Java_ContentViewClient_onJsPrompt(env,
|
| - weak_java_client_.get(env).obj(),
|
| + return Java_ContentViewClient_onJsPrompt(env, obj.obj(),
|
| jurl.obj(),
|
| jmessage.obj(),
|
| jdefault_value.obj());
|
| @@ -179,278 +172,6 @@ bool ContentViewClient::OnJSModalDialog(JavaScriptMessageType type,
|
| }
|
| }
|
|
|
| -// ----------------------------------------------------------------------------
|
| -// WebContentsDelegate methods
|
| -// ----------------------------------------------------------------------------
|
| -
|
| -// OpenURLFromTab() will be called when we're performing a browser-intiated
|
| -// navigation. The most common scenario for this is opening new tabs (see
|
| -// RenderViewImpl::decidePolicyForNavigation for more details).
|
| -WebContents* ContentViewClient::OpenURLFromTab(
|
| - WebContents* source,
|
| - const OpenURLParams& params) {
|
| - const GURL& url = params.url;
|
| - WindowOpenDisposition disposition = params.disposition;
|
| - PageTransition transition(
|
| - PageTransitionFromInt(params.transition));
|
| -
|
| - if (!source || (disposition != CURRENT_TAB &&
|
| - disposition != NEW_FOREGROUND_TAB &&
|
| - disposition != NEW_BACKGROUND_TAB &&
|
| - disposition != OFF_THE_RECORD)) {
|
| - NOTIMPLEMENTED();
|
| - return NULL;
|
| - }
|
| -
|
| - if (disposition == NEW_FOREGROUND_TAB ||
|
| - disposition == NEW_BACKGROUND_TAB ||
|
| - disposition == OFF_THE_RECORD) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - ScopedJavaLocalRef<jstring> java_url =
|
| - ConvertUTF8ToJavaString(env, url.spec());
|
| - Java_ContentViewClient_openNewTab(env,
|
| - weak_java_client_.get(env).obj(),
|
| - java_url.obj(),
|
| - disposition == OFF_THE_RECORD);
|
| - return NULL;
|
| - }
|
| -
|
| - // TODO(mkosiba): This should be in platform_utils OpenExternal, b/6174564.
|
| - if (transition == PAGE_TRANSITION_LINK && ShouldOverrideLoading(url))
|
| - return NULL;
|
| -
|
| - source->GetController().LoadURL(url, params.referrer, transition,
|
| - std::string());
|
| - return source;
|
| -}
|
| -
|
| -// ShouldIgnoreNavigation will be called for every non-local top level
|
| -// navigation made by the renderer. If true is returned the renderer will
|
| -// not perform the navigation. This is done by using synchronous IPC so we
|
| -// should avoid blocking calls from this method.
|
| -bool ContentViewClient::ShouldIgnoreNavigation(
|
| - WebContents* source,
|
| - const GURL& url,
|
| - const Referrer& referrer,
|
| - WindowOpenDisposition disposition,
|
| - PageTransition transition_type) {
|
| -
|
| - // Don't override new tabs.
|
| - if (disposition == NEW_FOREGROUND_TAB ||
|
| - disposition == NEW_BACKGROUND_TAB ||
|
| - disposition == OFF_THE_RECORD)
|
| - return false;
|
| -
|
| - // Don't override the navigation that has just been requested via the
|
| - // ContentView.loadUrl method.
|
| - if (url == last_requested_navigation_url_) {
|
| - last_requested_navigation_url_ = GURL::EmptyGURL();
|
| - return false;
|
| - }
|
| -
|
| - return ShouldOverrideLoading(url);
|
| -}
|
| -
|
| -void ContentViewClient::NavigationStateChanged(
|
| - const WebContents* source, unsigned changed_flags) {
|
| - if (changed_flags & (
|
| - INVALIDATE_TYPE_TAB | INVALIDATE_TYPE_TITLE)) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - Java_ContentViewClient_onTabHeaderStateChanged(
|
| - env, weak_java_client_.get(env).obj());
|
| - }
|
| -}
|
| -
|
| -void ContentViewClient::AddNewContents(WebContents* source,
|
| - WebContents* new_contents,
|
| - WindowOpenDisposition disposition,
|
| - const gfx::Rect& initial_pos,
|
| - bool user_gesture) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - bool handled = Java_ContentViewClient_addNewContents(
|
| - env,
|
| - weak_java_client_.get(env).obj(),
|
| - reinterpret_cast<jint>(source),
|
| - reinterpret_cast<jint>(new_contents),
|
| - static_cast<jint>(disposition),
|
| - NULL,
|
| - user_gesture);
|
| - if (!handled)
|
| - delete new_contents;
|
| -}
|
| -
|
| -void ContentViewClient::ActivateContents(WebContents* contents) {
|
| - // TODO(dtrainor) When doing the merge I came across this. Should we be
|
| - // activating this tab here?
|
| -}
|
| -
|
| -void ContentViewClient::DeactivateContents(WebContents* contents) {
|
| - // Do nothing.
|
| -}
|
| -
|
| -void ContentViewClient::LoadingStateChanged(WebContents* source) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - bool has_stopped = source == NULL || !source->IsLoading();
|
| -
|
| - if (has_stopped)
|
| - Java_ContentViewClient_onLoadStopped(
|
| - env, weak_java_client_.get(env).obj());
|
| - else
|
| - Java_ContentViewClient_onLoadStarted(
|
| - env, weak_java_client_.get(env).obj());
|
| -}
|
| -
|
| -void ContentViewClient::LoadProgressChanged(double progress) {
|
| - load_progress_ = progress;
|
| - JNIEnv* env = AttachCurrentThread();
|
| - Java_ContentViewClient_onLoadProgressChanged(
|
| - env,
|
| - weak_java_client_.get(env).obj(),
|
| - progress);
|
| -}
|
| -
|
| -double ContentViewClient::GetLoadProgress() const {
|
| - return load_progress_;
|
| -}
|
| -
|
| -void ContentViewClient::CloseContents(WebContents* source) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - Java_ContentViewClient_closeContents(env, weak_java_client_.get(env).obj());
|
| -}
|
| -
|
| -void ContentViewClient::MoveContents(WebContents* source,
|
| - const gfx::Rect& pos) {
|
| - // Do nothing.
|
| -}
|
| -
|
| -// TODO(merge): WARNING! method no longer available on the base class.
|
| -// See http://b/issue?id=5862108
|
| -void ContentViewClient::URLStarredChanged(WebContents* source, bool starred) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - Java_ContentViewClient_onUrlStarredChanged(env,
|
| - weak_java_client_.get(env).obj(),
|
| - starred);
|
| -}
|
| -
|
| -// This is either called from TabContents::DidNavigateMainFramePostCommit() with
|
| -// an empty GURL or responding to RenderViewHost::OnMsgUpateTargetURL(). In
|
| -// Chrome, the latter is not always called, especially not during history
|
| -// navigation. So we only handle the first case and pass the source TabContents'
|
| -// url to Java to update the UI.
|
| -void ContentViewClient::UpdateTargetURL(WebContents* source,
|
| - int32 page_id,
|
| - const GURL& url) {
|
| - if (url.is_empty()) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - ScopedJavaLocalRef<jstring> java_url =
|
| - ConvertUTF8ToJavaString(env, source->GetURL().spec());
|
| - Java_ContentViewClient_onUpdateUrl(env,
|
| - weak_java_client_.get(env).obj(),
|
| - java_url.obj());
|
| - }
|
| -}
|
| -
|
| -bool ContentViewClient::CanDownload(RenderViewHost* source,
|
| - int request_id,
|
| - const std::string& request_method) {
|
| - if (request_method == net::HttpRequestHeaders::kGetMethod) {
|
| - DownloadController::GetInstance()->CreateGETDownload(
|
| - source, request_id);
|
| - return false;
|
| - }
|
| - return true;
|
| -}
|
| -
|
| -void ContentViewClient::OnStartDownload(WebContents* source,
|
| - DownloadItem* download) {
|
| - DownloadController::GetInstance()->OnPostDownloadStarted(
|
| - source, download);
|
| -}
|
| -
|
| -void ContentViewClient::FindReply(WebContents* web_contents,
|
| - int request_id,
|
| - int number_of_matches,
|
| - const gfx::Rect& selection_rect,
|
| - int active_match_ordinal,
|
| - bool final_update) {
|
| - /* TODO(jrg): upstream this; requires
|
| - content/browser/android/find_helper.h to be upstreamed */
|
| -}
|
| -
|
| -void ContentViewClient::OnReceiveFindMatchRects(
|
| - int version, const std::vector<FindMatchRect>& rects,
|
| - const FindMatchRect& active_rect) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| -
|
| - // Constructs an float[] of (left, top, right, bottom) tuples and passes it on
|
| - // to the Java onReceiveFindMatchRects handler which will use it to create
|
| - // RectF objects equivalent to the std::vector<FindMatchRect>.
|
| - ScopedJavaLocalRef<jfloatArray> rect_data(env,
|
| - env->NewFloatArray(rects.size() * 4));
|
| - jfloat* rect_data_floats = env->GetFloatArrayElements(rect_data.obj(), NULL);
|
| - for (size_t i = 0; i < rects.size(); ++i) {
|
| - rect_data_floats[4 * i] = rects[i].left;
|
| - rect_data_floats[4 * i + 1] = rects[i].top;
|
| - rect_data_floats[4 * i + 2] = rects[i].right;
|
| - rect_data_floats[4 * i + 3] = rects[i].bottom;
|
| - }
|
| - env->ReleaseFloatArrayElements(rect_data.obj(), rect_data_floats, 0);
|
| -
|
| - ScopedJavaLocalRef<jobject> active_rect_object;
|
| - if (active_rect.left < active_rect.right &&
|
| - active_rect.top < active_rect.bottom) {
|
| - ScopedJavaLocalRef<jclass> rect_clazz =
|
| - GetClass(env, "android/graphics/RectF");
|
| - jmethodID rect_constructor =
|
| - GetMethodID(env, rect_clazz, "<init>", "(FFFF)V");
|
| - active_rect_object.Reset(env, env->NewObject(rect_clazz.obj(),
|
| - rect_constructor,
|
| - active_rect.left,
|
| - active_rect.top,
|
| - active_rect.right,
|
| - active_rect.bottom));
|
| - DCHECK(!active_rect_object.is_null());
|
| - }
|
| -
|
| -
|
| - Java_ContentViewClient_onReceiveFindMatchRects(
|
| - env,
|
| - weak_java_client_.get(env).obj(),
|
| - version, rect_data.obj(),
|
| - active_rect_object.obj());
|
| -}
|
| -
|
| -bool ContentViewClient::ShouldOverrideLoading(const GURL& url) {
|
| - if (!url.is_valid())
|
| - return false;
|
| -
|
| - JNIEnv* env = AttachCurrentThread();
|
| - ScopedJavaLocalRef<jstring> jstring_url =
|
| - ConvertUTF8ToJavaString(env, url.spec());
|
| - bool ret = Java_ContentViewClient_shouldOverrideUrlLoading(
|
| - env, weak_java_client_.get(env).obj(), jstring_url.obj());
|
| - return ret;
|
| -}
|
| -
|
| -void ContentViewClient::HandleKeyboardEvent(
|
| - const NativeWebKeyboardEvent& event) {
|
| - jobject key_event = KeyEventFromNative(event);
|
| - if (key_event) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - Java_ContentViewClient_handleKeyboardEvent(
|
| - env,
|
| - weak_java_client_.get(env).obj(),
|
| - key_event);
|
| - }
|
| -}
|
| -
|
| -bool ContentViewClient::TakeFocus(bool reverse) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - return Java_ContentViewClient_takeFocus(env,
|
| - weak_java_client_.get(env).obj(),
|
| - reverse);
|
| -}
|
| -
|
| ContentViewClientError ContentViewClient::ToContentViewClientError(
|
| int net_error) {
|
| // Note: many net::Error constants don't have an obvious mapping.
|
| @@ -554,18 +275,6 @@ ContentViewClientError ContentViewClient::ToContentViewClientError(
|
| }
|
| }
|
|
|
| -JavaScriptDialogCreator* ContentViewClient::GetJavaScriptDialogCreator() {
|
| - return javascript_dialog_creator_;
|
| -}
|
| -
|
| -void ContentViewClient::RunFileChooser(
|
| - WebContents* tab, const FileChooserParams& params) {
|
| - JNIEnv* env = AttachCurrentThread();
|
| - ScopedJavaLocalRef<jobject> jparams = ToJavaFileChooserParams(env, params);
|
| - Java_ContentViewClient_runFileChooser(env, weak_java_client_.get(env).obj(),
|
| - jparams.obj());
|
| -}
|
| -
|
| // ----------------------------------------------------------------------------
|
| // Native JNI methods
|
| // ----------------------------------------------------------------------------
|
|
|