Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: android_webview/native/aw_contents_io_thread_client_impl.cc

Issue 1544863002: [Android WebView] Implement initial settings and callback support for Service Workers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "android_webview/native/aw_contents_io_thread_client_impl.h" 5 #include "android_webview/native/aw_contents_io_thread_client_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "android_webview/common/devtools_instrumentation.h" 10 #include "android_webview/common/devtools_instrumentation.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 static LazyInstance<RfhToIoThreadClientMap> g_instance_; 78 static LazyInstance<RfhToIoThreadClientMap> g_instance_;
79 base::Lock map_lock_; 79 base::Lock map_lock_;
80 RenderFrameHostToIoThreadClientType rfh_to_io_thread_client_; 80 RenderFrameHostToIoThreadClientType rfh_to_io_thread_client_;
81 }; 81 };
82 82
83 // static 83 // static
84 LazyInstance<RfhToIoThreadClientMap> RfhToIoThreadClientMap::g_instance_ = 84 LazyInstance<RfhToIoThreadClientMap> RfhToIoThreadClientMap::g_instance_ =
85 LAZY_INSTANCE_INITIALIZER; 85 LAZY_INSTANCE_INITIALIZER;
86 86
87 // static 87 // static
88 LazyInstance<JavaObjectWeakGlobalRef> g_sw_instance_ =
89 LAZY_INSTANCE_INITIALIZER;
90
91 // static
88 RfhToIoThreadClientMap* RfhToIoThreadClientMap::GetInstance() { 92 RfhToIoThreadClientMap* RfhToIoThreadClientMap::GetInstance() {
89 return g_instance_.Pointer(); 93 return g_instance_.Pointer();
90 } 94 }
91 95
92 void RfhToIoThreadClientMap::Set(pair<int, int> rfh_id, 96 void RfhToIoThreadClientMap::Set(pair<int, int> rfh_id,
93 const IoThreadClientData& client) { 97 const IoThreadClientData& client) {
94 base::AutoLock lock(map_lock_); 98 base::AutoLock lock(map_lock_);
95 rfh_to_io_thread_client_[rfh_id] = client; 99 rfh_to_io_thread_client_[rfh_id] = client;
96 } 100 }
97 101
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 251
248 // static 252 // static
249 void AwContentsIoThreadClientImpl::Associate( 253 void AwContentsIoThreadClientImpl::Associate(
250 WebContents* web_contents, 254 WebContents* web_contents,
251 const JavaRef<jobject>& jclient) { 255 const JavaRef<jobject>& jclient) {
252 JNIEnv* env = AttachCurrentThread(); 256 JNIEnv* env = AttachCurrentThread();
253 // The ClientMapEntryUpdater lifespan is tied to the WebContents. 257 // The ClientMapEntryUpdater lifespan is tied to the WebContents.
254 new ClientMapEntryUpdater(env, web_contents, jclient.obj()); 258 new ClientMapEntryUpdater(env, web_contents, jclient.obj());
255 } 259 }
256 260
261 // static
262 void AwContentsIoThreadClientImpl::SetServiceWorkerIoThreadClient(
263 const base::android::JavaRef<jobject>& jclient,
264 const base::android::JavaRef<jobject>& browser_context) {
265 // TODO: currently there is only one browser context so it is ok to
266 // store in a global variable, in the future use browser_context to
267 // obtain the correct instance.
268 JavaObjectWeakGlobalRef temp(AttachCurrentThread(), jclient.obj());
269 g_sw_instance_.Get() = temp;
270 }
271
272 // static
273 scoped_ptr<AwContentsIoThreadClient>
274 AwContentsIoThreadClient::GetServiceWorkerIoThreadClient() {
275 if (g_sw_instance_.Get().is_empty())
276 return scoped_ptr<AwContentsIoThreadClient>();
277
278 JNIEnv* env = AttachCurrentThread();
279 ScopedJavaLocalRef<jobject> java_delegate = g_sw_instance_.Get().get(env);
280
281 DCHECK(!java_delegate.is_null());
282 return scoped_ptr<AwContentsIoThreadClient>(new AwContentsIoThreadClientImpl(
283 false, java_delegate));
284 }
285
257 AwContentsIoThreadClientImpl::AwContentsIoThreadClientImpl( 286 AwContentsIoThreadClientImpl::AwContentsIoThreadClientImpl(
258 bool pending_association, 287 bool pending_association,
259 const JavaRef<jobject>& obj) 288 const JavaRef<jobject>& obj)
260 : pending_association_(pending_association), 289 : pending_association_(pending_association),
261 java_object_(obj) { 290 java_object_(obj) {
262 } 291 }
263 292
264 AwContentsIoThreadClientImpl::~AwContentsIoThreadClientImpl() { 293 AwContentsIoThreadClientImpl::~AwContentsIoThreadClientImpl() {
265 // explict, out-of-line destructor. 294 // explict, out-of-line destructor.
266 } 295 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 jstring_reason.obj(), 533 jstring_reason.obj(),
505 jstringArray_response_header_names.obj(), 534 jstringArray_response_header_names.obj(),
506 jstringArray_response_header_values.obj()); 535 jstringArray_response_header_values.obj());
507 } 536 }
508 537
509 bool RegisterAwContentsIoThreadClientImpl(JNIEnv* env) { 538 bool RegisterAwContentsIoThreadClientImpl(JNIEnv* env) {
510 return RegisterNativesImpl(env); 539 return RegisterNativesImpl(env);
511 } 540 }
512 541
513 } // namespace android_webview 542 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/aw_contents_io_thread_client_impl.h ('k') | android_webview/native/aw_contents_statics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698