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

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp

Issue 1196193003: ServiceWorker: Implement navigate() method in WindowClient (blink side). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" 6 #include "modules/serviceworkers/ServiceWorkerWindowClient.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/page/PageVisibilityState.h" 12 #include "core/page/PageVisibilityState.h"
13 #include "core/workers/WorkerGlobalScope.h"
14 #include "core/workers/WorkerLocation.h"
13 #include "modules/serviceworkers/ServiceWorkerError.h" 15 #include "modules/serviceworkers/ServiceWorkerError.h"
14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" 16 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
15 #include "public/platform/WebString.h" 17 #include "public/platform/WebString.h"
16 #include "wtf/RefPtr.h" 18 #include "wtf/RefPtr.h"
17 19
18 namespace blink { 20 namespace blink {
19 21
20 ServiceWorkerWindowClient* ServiceWorkerWindowClient::take(ScriptPromiseResolver *, PassOwnPtr<ServiceWorkerWindowClient::WebType> webClient) 22 ServiceWorkerWindowClient* ServiceWorkerWindowClient::take(ScriptPromiseResolver *, PassOwnPtr<ServiceWorkerWindowClient::WebType> webClient)
21 { 23 {
22 return ServiceWorkerWindowClient::create(*webClient); 24 return ServiceWorkerWindowClient::create(*webClient);
(...skipping 28 matching lines...) Expand all
51 if (!scriptState->executionContext()->isWindowInteractionAllowed()) { 53 if (!scriptState->executionContext()->isWindowInteractionAllowed()) {
52 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o focus a window.")); 54 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o focus a window."));
53 return promise; 55 return promise;
54 } 56 }
55 scriptState->executionContext()->consumeWindowInteraction(); 57 scriptState->executionContext()->consumeWindowInteraction();
56 58
57 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus (uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro r>(resolver)); 59 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus (uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro r>(resolver));
58 return promise; 60 return promise;
59 } 61 }
60 62
63 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* scriptState, cons t String& url)
64 {
65 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
66 ScriptPromise promise = resolver->promise();
67 ExecutionContext* context = scriptState->executionContext();
68
69 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url);
70 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) {
71 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate( ), "'" + url + "' is not a valid URL."));
72 return promise;
73 }
74 if (!context->securityOrigin()->canDisplay(parsedUrl)) {
75 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.eli dedString() + "' cannot navigate."));
76 return promise;
77 }
78
79 ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, n ew CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolve r));
80 return promise;
81 }
82
61 DEFINE_TRACE(ServiceWorkerWindowClient) 83 DEFINE_TRACE(ServiceWorkerWindowClient)
62 { 84 {
63 ServiceWorkerClient::trace(visitor); 85 ServiceWorkerClient::trace(visitor);
64 } 86 }
65 87
66 } // namespace blink 88 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerWindowClient.h ('k') | Source/modules/serviceworkers/WindowClient.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698