Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/favicon_status.h" | 23 #include "content/public/browser/favicon_status.h" |
| 24 #include "content/public/browser/interstitial_page.h" | 24 #include "content/public/browser/interstitial_page.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
| 27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
| 29 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/common/content_client.h" | 31 #include "content/public/common/content_client.h" |
| 32 #include "content/public/common/frame_navigate_params.h" | |
| 32 #include "content/public/common/page_transition_types.h" | 33 #include "content/public/common/page_transition_types.h" |
| 33 #include "jni/ContentViewCore_jni.h" | 34 #include "jni/ContentViewCore_jni.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h" |
| 37 #include "ui/gfx/android/java_bitmap.h" | 38 #include "ui/gfx/android/java_bitmap.h" |
| 38 #include "ui/gfx/android/window_android.h" | 39 #include "ui/gfx/android/window_android.h" |
| 39 #include "webkit/glue/webmenuitem.h" | 40 #include "webkit/glue/webmenuitem.h" |
| 40 #include "webkit/user_agent/user_agent_util.h" | 41 #include "webkit/user_agent/user_agent_util.h" |
| 41 | 42 |
| 42 using base::android::AttachCurrentThread; | 43 using base::android::AttachCurrentThread; |
| 43 using base::android::ConvertJavaStringToUTF16; | 44 using base::android::ConvertJavaStringToUTF16; |
| 44 using base::android::ConvertJavaStringToUTF8; | 45 using base::android::ConvertJavaStringToUTF8; |
| 45 using base::android::ConvertUTF16ToJavaString; | 46 using base::android::ConvertUTF16ToJavaString; |
| 46 using base::android::ConvertUTF8ToJavaString; | 47 using base::android::ConvertUTF8ToJavaString; |
| 48 using base::android::CheckException; | |
| 47 using base::android::GetClass; | 49 using base::android::GetClass; |
| 48 using base::android::HasField; | 50 using base::android::HasField; |
| 49 using base::android::JavaByteArrayToByteVector; | 51 using base::android::JavaByteArrayToByteVector; |
| 50 using base::android::ScopedJavaGlobalRef; | 52 using base::android::ScopedJavaGlobalRef; |
| 51 using base::android::ScopedJavaLocalRef; | 53 using base::android::ScopedJavaLocalRef; |
| 52 using WebKit::WebInputEvent; | 54 using WebKit::WebInputEvent; |
| 53 using WebKit::WebInputEventFactory; | 55 using WebKit::WebInputEventFactory; |
| 54 | 56 |
| 55 // Describes the type and enabled state of a select popup item. | 57 // Describes the type and enabled state of a select popup item. |
| 56 // Keep in sync with the value defined in SelectPopupDialog.java | 58 // Keep in sync with the value defined in SelectPopupDialog.java |
| 57 enum PopupItemType { | 59 enum PopupItemType { |
| 58 POPUP_ITEM_TYPE_GROUP = 0, | 60 POPUP_ITEM_TYPE_GROUP = 0, |
| 59 POPUP_ITEM_TYPE_DISABLED, | 61 POPUP_ITEM_TYPE_DISABLED, |
| 60 POPUP_ITEM_TYPE_ENABLED | 62 POPUP_ITEM_TYPE_ENABLED |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 namespace { | 65 namespace { |
| 64 jfieldID g_native_content_view; | 66 jfieldID g_native_content_view; |
| 65 } // namespace | 67 } // namespace |
| 66 | 68 |
| 67 namespace content { | 69 namespace content { |
| 68 | 70 |
| 69 struct ContentViewCoreImpl::JavaObject { | 71 struct ContentViewCoreImpl::JavaObject { |
| 70 | 72 |
| 71 }; | 73 }; |
| 72 | 74 |
| 75 // static | |
| 76 ContentViewCore* ContentViewCore::FromWebContents(WebContents* web_contents) { | |
| 77 return web_contents->GetContentNativeView(); | |
| 78 } | |
| 79 | |
| 80 // static | |
| 73 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, | 81 ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, |
| 74 jobject obj) { | 82 jobject obj) { |
| 75 return reinterpret_cast<ContentViewCore*>( | 83 return reinterpret_cast<ContentViewCore*>( |
| 76 env->GetIntField(obj, g_native_content_view)); | 84 env->GetIntField(obj, g_native_content_view)); |
| 77 } | 85 } |
| 78 | 86 |
| 87 class ContentViewCoreImpl::ContentViewWebContentsObserver | |
| 88 : public WebContentsObserver { | |
| 89 public: | |
| 90 ContentViewWebContentsObserver(WebContents* web_contents, | |
| 91 ContentViewCoreImpl* parent); | |
| 92 virtual ~ContentViewWebContentsObserver(); | |
| 93 | |
| 94 private: | |
| 95 // WebContentsObserver | |
| 96 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE; | |
| 97 virtual void DidStartLoading(RenderViewHost* render_view_host) OVERRIDE; | |
| 98 virtual void DidStartProvisionalLoadForFrame( | |
| 99 int64 frame_id, | |
| 100 bool is_main_frame, | |
| 101 const GURL& validated_url, | |
| 102 bool is_error_page, | |
| 103 RenderViewHost* render_view_host) OVERRIDE; | |
| 104 virtual void DidFailProvisionalLoad( | |
| 105 int64 frame_id, | |
| 106 bool is_main_frame, | |
| 107 const GURL& validated_url, | |
| 108 int error_code, | |
| 109 const string16& error_description, | |
| 110 RenderViewHost* render_view_host) OVERRIDE; | |
| 111 virtual void DidFailLoad(int64 frame_id, | |
| 112 const GURL& validated_url, | |
| 113 bool is_main_frame, | |
| 114 int error_code, | |
| 115 const string16& error_description, | |
| 116 RenderViewHost* render_view_host) OVERRIDE; | |
| 117 virtual void DidFinishLoad(int64 frame_id, | |
| 118 const GURL& validated_url, | |
| 119 bool is_main_frame, | |
| 120 RenderViewHost* render_view_host) OVERRIDE; | |
| 121 virtual void DidNavigateMainFrame( | |
| 122 const LoadCommittedDetails& details, | |
| 123 const FrameNavigateParams& params) OVERRIDE; | |
| 124 | |
| 125 NotificationRegistrar registrar_; | |
| 126 | |
| 127 ContentViewCoreImpl* parent_; | |
| 128 | |
| 129 DISALLOW_COPY_AND_ASSIGN(ContentViewWebContentsObserver); | |
| 130 }; | |
| 131 | |
| 132 ContentViewCoreImpl::ContentViewWebContentsObserver:: | |
| 133 ContentViewWebContentsObserver(WebContents* web_contents, | |
| 134 ContentViewCoreImpl* parent) | |
| 135 : WebContentsObserver(web_contents), | |
| 136 parent_(parent) { | |
| 137 } | |
| 138 | |
| 139 ContentViewCoreImpl::ContentViewWebContentsObserver:: | |
| 140 ~ContentViewWebContentsObserver() { | |
| 141 } | |
| 142 | |
| 143 void ContentViewCoreImpl::ContentViewWebContentsObserver:: | |
| 144 WebContentsDestroyed(WebContents* web_contents) { | |
| 145 parent_->DetachWebContents(web_contents); | |
| 146 } | |
| 147 | |
| 148 void ContentViewCoreImpl::ContentViewWebContentsObserver::DidStartLoading( | |
| 149 RenderViewHost* render_view_host) { | |
| 150 parent_->DidStartLoading(); | |
| 151 } | |
| 152 | |
| 153 void ContentViewCoreImpl::ContentViewWebContentsObserver:: | |
| 154 DidStartProvisionalLoadForFrame(int64 frame_id, | |
| 155 bool is_main_frame, | |
| 156 const GURL& validated_url, | |
| 157 bool is_error_page, | |
| 158 RenderViewHost* render_view_host) { | |
| 159 // Don't report status for page components like iframes to comply with legacy | |
| 160 // WebView behavior. | |
| 161 if (is_main_frame) | |
| 162 parent_->OnPageStarted(validated_url); | |
| 163 } | |
| 164 | |
| 165 void ContentViewCoreImpl::ContentViewWebContentsObserver:: | |
| 166 DidFailProvisionalLoad(int64 frame_id, | |
| 167 bool is_main_frame, | |
| 168 const GURL& validated_url, | |
| 169 int error_code, | |
| 170 const string16& error_description, | |
| 171 RenderViewHost* render_view_host) { | |
| 172 // Don't report status for page components like iframes to comply with legacy | |
| 173 // WebView behavior. | |
| 174 if (is_main_frame) | |
| 175 parent_->OnPageFailed(error_code, error_description, validated_url); | |
| 176 } | |
| 177 | |
| 178 void ContentViewCoreImpl::ContentViewWebContentsObserver::DidFailLoad( | |
| 179 int64 frame_id, const GURL& validated_url, bool is_main_frame, | |
| 180 int error_code, const string16& error_description, | |
| 181 RenderViewHost* render_view_host) { | |
| 182 // This is reported only for legacy WebView compatibility. The browser only | |
| 183 // needs to be notified of provisional load failures. | |
| 184 if (is_main_frame) | |
| 185 parent_->OnPageFailed(error_code, error_description, validated_url); | |
| 186 } | |
| 187 | |
| 188 void ContentViewCoreImpl::ContentViewWebContentsObserver::DidFinishLoad( | |
| 189 int64 frame_id, const GURL& validated_url, bool is_main_frame, | |
| 190 RenderViewHost* render_view_host) { | |
| 191 // Don't report status for page components like iframes to comply with legacy | |
| 192 // WebView behavior. | |
| 193 if (is_main_frame) | |
| 194 parent_->OnPageFinished(validated_url); | |
| 195 } | |
| 196 | |
| 197 void ContentViewCoreImpl::ContentViewWebContentsObserver:: | |
| 198 DidNavigateMainFrame( | |
| 199 const LoadCommittedDetails& details, | |
| 200 const FrameNavigateParams& params) { | |
| 201 parent_->OnDidCommitMainFrame(params.url, params.base_url); | |
| 202 } | |
| 79 | 203 |
| 80 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, | 204 ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, |
| 81 bool hardware_accelerated, | 205 bool hardware_accelerated, |
| 82 bool take_ownership_of_web_contents, | 206 bool take_ownership_of_web_contents, |
| 83 WebContents* web_contents, | 207 WebContents* web_contents, |
| 84 ui::WindowAndroid* window_android) | 208 ui::WindowAndroid* window_android) |
| 85 : java_ref_(env, obj), | 209 : java_ref_(env, obj), |
| 86 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 210 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 87 owns_web_contents_(take_ownership_of_web_contents), | 211 owns_web_contents_(take_ownership_of_web_contents), |
| 88 tab_crashed_(false), | 212 tab_crashed_(false), |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 112 } | 236 } |
| 113 | 237 |
| 114 ContentViewCoreImpl::~ContentViewCoreImpl() { | 238 ContentViewCoreImpl::~ContentViewCoreImpl() { |
| 115 // Make sure nobody calls back into this object while we are tearing things | 239 // Make sure nobody calls back into this object while we are tearing things |
| 116 // down. | 240 // down. |
| 117 notification_registrar_.RemoveAll(); | 241 notification_registrar_.RemoveAll(); |
| 118 | 242 |
| 119 delete java_object_; | 243 delete java_object_; |
| 120 java_object_ = NULL; | 244 java_object_ = NULL; |
| 121 java_ref_.reset(); | 245 java_ref_.reset(); |
| 246 | |
| 247 if (owns_web_contents_) { | |
| 248 delete web_contents_; | |
| 249 } else { | |
| 250 DetachWebContents(web_contents_); | |
| 251 } | |
| 122 } | 252 } |
| 123 | 253 |
| 124 void ContentViewCoreImpl::Destroy(JNIEnv* env, jobject obj) { | 254 void ContentViewCoreImpl::Destroy(JNIEnv* env, jobject obj) { |
| 125 delete this; | 255 delete this; |
| 126 } | 256 } |
| 127 | 257 |
| 128 void ContentViewCoreImpl::InitWebContents(WebContents* web_contents) { | 258 void ContentViewCoreImpl::InitWebContents(WebContents* web_contents) { |
| 129 web_contents_ = static_cast<WebContentsImpl*>(web_contents); | 259 web_contents_ = static_cast<WebContentsImpl*>(web_contents); |
| 130 notification_registrar_.Add(this, | 260 notification_registrar_.Add(this, |
| 131 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 261 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
| 132 Source<NavigationController>(&web_contents_->GetController())); | 262 Source<NavigationController>(&web_contents_->GetController())); |
| 133 | 263 |
| 134 static_cast<WebContentsViewAndroid*>(web_contents_->GetView())-> | 264 static_cast<WebContentsViewAndroid*>(web_contents_->GetView())-> |
| 135 SetContentViewCore(this); | 265 SetContentViewCore(this); |
| 266 | |
| 267 web_contents_observer_.reset( | |
| 268 new ContentViewWebContentsObserver(web_contents_, this)); | |
| 269 } | |
| 270 | |
| 271 void ContentViewCoreImpl::ReplaceWebContents( | |
| 272 WebContents* old_web_contents, | |
| 273 WebContents* new_web_contents) { | |
| 274 DCHECK(old_web_contents == web_contents_); | |
| 275 notification_registrar_.Remove(this, | |
| 276 NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | |
| 277 Source<NavigationController>(&web_contents_->GetController())); | |
| 278 | |
| 279 // Since we only use the bottom portion of the prerender stack, we have | |
| 280 // to take care of everything incl. showing the new view ourselves. | |
| 281 old_web_contents->GetRenderWidgetHostView()->Hide(); | |
| 282 | |
| 283 // Note that we are not deleting web_contents_ irrespective of | |
| 284 // owns_web_contents_: it's the caller responsibility to delete it. | |
| 285 // Note also that we don't change owns_web_contents_, so we'll own the new | |
| 286 // WebContents if we owned the old one. | |
| 287 InitWebContents(new_web_contents); | |
| 288 | |
| 289 new_web_contents->GetRenderWidgetHostView()->Show(); | |
| 290 } | |
| 291 | |
| 292 WebContents* ContentViewCoreImpl::AcquireWebContents() { | |
| 293 DCHECK(owns_web_contents_); | |
| 294 owns_web_contents_ = false; | |
| 295 return web_contents_; | |
| 296 } | |
| 297 | |
| 298 void ContentViewCoreImpl::DetachWebContents(WebContents* web_contents) { | |
| 299 if (web_contents_) { | |
| 300 DCHECK(web_contents_ == web_contents); | |
| 301 | |
| 302 static_cast<WebContentsViewAndroid*>( | |
| 303 web_contents_->GetView())->SetContentViewCore( | |
| 304 base::WeakPtr<ContentViewCoreImpl>()); | |
| 305 | |
| 306 // Terminate the renderer process if this is the last tab. | |
| 307 // If there's no unload listener, FastShutdownForPageCount kills the | |
| 308 // renderer process. Otherwise, we go with the slow path where renderer | |
| 309 // process shuts down itself when ref count becomes 0. | |
| 310 RenderProcessHost* process = web_contents_->GetRenderProcessHost(); | |
| 311 process->FastShutdownForPageCount(1); | |
| 312 | |
| 313 web_contents_ = NULL; | |
| 314 owns_web_contents_ = false; | |
| 315 | |
| 316 // NOTE: since it's possible that the web_contents_ pointer can be cleared | |
| 317 // out, we should really be checking if it's NULL before each use. However, | |
| 318 // this really shouldn't happen in practice - right now, it only happens | |
| 319 // when a Tab is deleted (which deletes WebContents) but the | |
| 320 // ContentViewCore associated with the Tab is not. This only occurs when | |
| 321 // code is explicitly changed for some type of testing. Because of this, | |
| 322 // references to web_contents_ are generally not guarded. | |
| 323 } | |
| 136 } | 324 } |
| 137 | 325 |
| 138 void ContentViewCoreImpl::Observe(int type, | 326 void ContentViewCoreImpl::Observe(int type, |
| 139 const NotificationSource& source, | 327 const NotificationSource& source, |
| 140 const NotificationDetails& details) { | 328 const NotificationDetails& details) { |
| 141 switch (type) { | 329 switch (type) { |
| 142 case NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT: { | 330 case NOTIFICATION_EXECUTE_JAVASCRIPT_RESULT: { |
| 143 if (!web_contents_ || Source<RenderViewHost>(source).ptr() != | 331 if (!web_contents_ || Source<RenderViewHost>(source).ptr() != |
| 144 web_contents_->GetRenderViewHost()) { | 332 web_contents_->GetRenderViewHost()) { |
| 145 return; | 333 return; |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 ScopedJavaLocalRef<jobject> j_bitmap; | 701 ScopedJavaLocalRef<jobject> j_bitmap; |
| 514 const FaviconStatus& status = entry->GetFavicon(); | 702 const FaviconStatus& status = entry->GetFavicon(); |
| 515 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) { | 703 if (status.valid && status.image.ToSkBitmap()->getSize() > 0) { |
| 516 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); | 704 j_bitmap = gfx::ConvertToJavaBitmap(status.image.ToSkBitmap()); |
| 517 } | 705 } |
| 518 | 706 |
| 519 // Add the item to the list | 707 // Add the item to the list |
| 520 Java_ContentViewCore_addToNavigationHistory(env, obj, context, j_url.obj(), | 708 Java_ContentViewCore_addToNavigationHistory(env, obj, context, j_url.obj(), |
| 521 j_virtual_url.obj(), j_original_url.obj(), j_title.obj(), | 709 j_virtual_url.obj(), j_original_url.obj(), j_title.obj(), |
| 522 j_bitmap.obj()); | 710 j_bitmap.obj()); |
| 711 CheckException(env); | |
|
Yaron
2012/09/20 04:13:53
Should be done automatically by jni-generator
| |
| 523 } | 712 } |
| 524 | 713 |
| 525 return controller.GetCurrentEntryIndex(); | 714 return controller.GetCurrentEntryIndex(); |
| 526 } | 715 } |
| 527 | 716 |
| 528 int ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { | 717 int ContentViewCoreImpl::GetNativeImeAdapter(JNIEnv* env, jobject obj) { |
| 529 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); | 718 RenderWidgetHostViewAndroid* rwhva = GetRenderWidgetHostViewAndroid(); |
| 530 if (!rwhva) | 719 if (!rwhva) |
| 531 return 0; | 720 return 0; |
| 532 return rwhva->GetNativeImeAdapter(); | 721 return rwhva->GetNativeImeAdapter(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 } | 760 } |
| 572 | 761 |
| 573 // -------------------------------------------------------------------------- | 762 // -------------------------------------------------------------------------- |
| 574 // Public methods that call to Java via JNI | 763 // Public methods that call to Java via JNI |
| 575 // -------------------------------------------------------------------------- | 764 // -------------------------------------------------------------------------- |
| 576 | 765 |
| 577 void ContentViewCoreImpl::OnTabCrashed(const base::ProcessHandle handle) { | 766 void ContentViewCoreImpl::OnTabCrashed(const base::ProcessHandle handle) { |
| 578 NOTIMPLEMENTED() << "not upstreamed yet"; | 767 NOTIMPLEMENTED() << "not upstreamed yet"; |
| 579 } | 768 } |
| 580 | 769 |
| 770 // Called from UI thread | |
| 771 void ContentViewCoreImpl::Invalidate() { | |
| 772 JNIEnv* env = AttachCurrentThread(); | |
| 773 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 774 if (obj.is_null()) | |
| 775 return; | |
| 776 Java_ContentViewCore_invalidate(env, obj.obj()); | |
| 777 } | |
| 778 | |
| 779 // Called from non-UI thread | |
| 780 void ContentViewCoreImpl::PostInvalidate() { | |
| 781 JNIEnv* env = AttachCurrentThread(); | |
| 782 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 783 if (obj.is_null()) | |
| 784 return; | |
| 785 Java_ContentViewCore_postInvalidate(env, obj.obj()); | |
| 786 } | |
| 787 | |
| 581 void ContentViewCoreImpl::ImeUpdateAdapter(int native_ime_adapter, | 788 void ContentViewCoreImpl::ImeUpdateAdapter(int native_ime_adapter, |
| 582 int text_input_type, | 789 int text_input_type, |
| 583 const std::string& text, | 790 const std::string& text, |
| 584 int selection_start, | 791 int selection_start, |
| 585 int selection_end, | 792 int selection_end, |
| 586 int composition_start, | 793 int composition_start, |
| 587 int composition_end, | 794 int composition_end, |
| 588 bool show_ime_if_needed) { | 795 bool show_ime_if_needed) { |
| 589 JNIEnv* env = AttachCurrentThread(); | 796 JNIEnv* env = AttachCurrentThread(); |
| 590 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 797 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 } | 896 } |
| 690 | 897 |
| 691 void ContentViewCoreImpl::DidStartLoading() { | 898 void ContentViewCoreImpl::DidStartLoading() { |
| 692 JNIEnv* env = AttachCurrentThread(); | 899 JNIEnv* env = AttachCurrentThread(); |
| 693 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 900 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 694 if (j_obj.is_null()) | 901 if (j_obj.is_null()) |
| 695 return; | 902 return; |
| 696 Java_ContentViewCore_didStartLoading(env, j_obj.obj()); | 903 Java_ContentViewCore_didStartLoading(env, j_obj.obj()); |
| 697 } | 904 } |
| 698 | 905 |
| 906 void ContentViewCoreImpl::OnPageStarted(const GURL& validated_url) { | |
| 907 if (content_view_client_.get()) | |
| 908 content_view_client_->OnPageStarted(validated_url); | |
| 909 JNIEnv* env = AttachCurrentThread(); | |
| 910 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 911 if (obj.is_null()) | |
| 912 return; | |
| 913 Java_ContentViewCore_onPageStarted(env, obj.obj()); | |
| 914 } | |
| 915 | |
| 916 void ContentViewCoreImpl::OnPageFinished(const GURL& validated_url) { | |
| 917 if (content_view_client_.get()) | |
| 918 content_view_client_->OnPageFinished(validated_url); | |
| 919 | |
| 920 JNIEnv* env = AttachCurrentThread(); | |
| 921 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 922 if (obj.is_null()) | |
| 923 return; | |
| 924 ScopedJavaLocalRef<jstring> jvalidated_url = | |
| 925 ConvertUTF8ToJavaString(env, validated_url.spec()); | |
| 926 Java_ContentViewCore_onPageFinished(env, obj.obj(), jvalidated_url.obj()); | |
| 927 } | |
| 928 | |
| 929 void ContentViewCoreImpl::OnDidCommitMainFrame(const GURL& url, | |
| 930 const GURL& base_url) { | |
| 931 if (content_view_client_.get()) | |
| 932 content_view_client_->OnDidCommitMainFrame(url, base_url); | |
| 933 } | |
| 934 | |
| 935 void ContentViewCoreImpl::OnPageFailed(int error_code, | |
| 936 const string16& description, | |
| 937 const GURL& failing_url) { | |
| 938 if (content_view_client_.get()) | |
| 939 content_view_client_->OnReceivedError(error_code, description, failing_url); | |
| 940 OnPageFinished(failing_url); | |
| 941 } | |
| 942 | |
| 699 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { | 943 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { |
| 700 JNIEnv* env = AttachCurrentThread(); | 944 JNIEnv* env = AttachCurrentThread(); |
| 701 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 945 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 702 if (j_obj.is_null()) | 946 if (j_obj.is_null()) |
| 703 return; | 947 return; |
| 704 ScopedJavaLocalRef<jstring> jcontent_url = | 948 ScopedJavaLocalRef<jstring> jcontent_url = |
| 705 ConvertUTF8ToJavaString(env, content_url.spec()); | 949 ConvertUTF8ToJavaString(env, content_url.spec()); |
| 706 Java_ContentViewCore_startContentIntent(env, | 950 Java_ContentViewCore_startContentIntent(env, |
| 707 j_obj.obj(), | 951 j_obj.obj(), |
| 708 jcontent_url.obj()); | 952 jcontent_url.obj()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 728 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 972 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
| 729 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 973 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
| 730 return false; | 974 return false; |
| 731 } | 975 } |
| 732 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 976 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
| 733 | 977 |
| 734 return RegisterNativesImpl(env) >= 0; | 978 return RegisterNativesImpl(env) >= 0; |
| 735 } | 979 } |
| 736 | 980 |
| 737 } // namespace content | 981 } // namespace content |
| OLD | NEW |