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

Side by Side Diff: Source/bindings/core/v8/custom/V8WindowCustom.cpp

Issue 670893003: Add window.postMessage() use counters. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | Source/core/frame/UseCounter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "bindings/core/v8/V8Node.h" 47 #include "bindings/core/v8/V8Node.h"
48 #include "core/dom/DOMArrayBuffer.h" 48 #include "core/dom/DOMArrayBuffer.h"
49 #include "core/dom/ExceptionCode.h" 49 #include "core/dom/ExceptionCode.h"
50 #include "core/dom/MessagePort.h" 50 #include "core/dom/MessagePort.h"
51 #include "core/frame/DOMTimer.h" 51 #include "core/frame/DOMTimer.h"
52 #include "core/frame/DOMWindowTimers.h" 52 #include "core/frame/DOMWindowTimers.h"
53 #include "core/frame/FrameView.h" 53 #include "core/frame/FrameView.h"
54 #include "core/frame/LocalDOMWindow.h" 54 #include "core/frame/LocalDOMWindow.h"
55 #include "core/frame/LocalFrame.h" 55 #include "core/frame/LocalFrame.h"
56 #include "core/frame/Settings.h" 56 #include "core/frame/Settings.h"
57 #include "core/frame/UseCounter.h"
57 #include "core/frame/csp/ContentSecurityPolicy.h" 58 #include "core/frame/csp/ContentSecurityPolicy.h"
58 #include "core/html/HTMLCollection.h" 59 #include "core/html/HTMLCollection.h"
59 #include "core/html/HTMLDocument.h" 60 #include "core/html/HTMLDocument.h"
60 #include "core/inspector/ScriptCallStack.h" 61 #include "core/inspector/ScriptCallStack.h"
61 #include "core/loader/FrameLoadRequest.h" 62 #include "core/loader/FrameLoadRequest.h"
62 #include "core/loader/FrameLoader.h" 63 #include "core/loader/FrameLoader.h"
63 #include "core/storage/Storage.h" 64 #include "core/storage/Storage.h"
64 #include "platform/PlatformScreen.h" 65 #include "platform/PlatformScreen.h"
65 #include "platform/graphics/media/MediaPlayer.h" 66 #include "platform/graphics/media/MediaPlayer.h"
66 #include "wtf/Assertions.h" 67 #include "wtf/Assertions.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 239 }
239 240
240 241
241 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info) 242 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info)
242 { 243 {
243 // None of these need to be RefPtr because info and context are guaranteed 244 // None of these need to be RefPtr because info and context are guaranteed
244 // to hold on to them. 245 // to hold on to them.
245 LocalDOMWindow* window = V8Window::toImpl(info.Holder()); 246 LocalDOMWindow* window = V8Window::toImpl(info.Holder());
246 LocalDOMWindow* source = callingDOMWindow(info.GetIsolate()); 247 LocalDOMWindow* source = callingDOMWindow(info.GetIsolate());
247 248
249 ASSERT(window);
250 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->document(), U seCounter::WindowPostMessage);
Mike West 2014/10/22 07:57:01 Aside: Ooh. countIfNotPrivateScript is... verbose.
sof 2014/10/22 08:00:33 Added a couple of days ago, https://codereview.chr
251
248 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", "Window", info.Holder(), info.GetIsolate()); 252 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", "Window", info.Holder(), info.GetIsolate());
249 253
250 // If called directly by WebCore we don't have a calling context. 254 // If called directly by WebCore we don't have a calling context.
251 if (!source) { 255 if (!source) {
252 exceptionState.throwTypeError("No active calling context exists."); 256 exceptionState.throwTypeError("No active calling context exists.");
253 exceptionState.throwIfNeeded(); 257 exceptionState.throwIfNeeded();
254 return; 258 return;
255 } 259 }
256 260
257 // This function has variable arguments and can be: 261 // This function has variable arguments and can be:
258 // Per current spec: 262 // Per current spec:
259 // postMessage(message, targetOrigin) 263 // postMessage(message, targetOrigin)
260 // postMessage(message, targetOrigin, {sequence of transferrables}) 264 // postMessage(message, targetOrigin, {sequence of transferrables})
261 // Legacy non-standard implementations in webkit allowed: 265 // Legacy non-standard implementations in webkit allowed:
262 // postMessage(message, {sequence of transferrables}, targetOrigin); 266 // postMessage(message, {sequence of transferrables}, targetOrigin);
263 MessagePortArray portArray; 267 MessagePortArray portArray;
264 ArrayBufferArray arrayBufferArray; 268 ArrayBufferArray arrayBufferArray;
265 int targetOriginArgIndex = 1; 269 int targetOriginArgIndex = 1;
266 if (info.Length() > 2) { 270 if (info.Length() > 2) {
267 int transferablesArgIndex = 2; 271 int transferablesArgIndex = 2;
268 if (isLegacyTargetOriginDesignation(info[2])) { 272 if (isLegacyTargetOriginDesignation(info[2])) {
273 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->docum ent(), UseCounter::WindowPostMessageWithLegacyTargetOriginArgument);
269 targetOriginArgIndex = 2; 274 targetOriginArgIndex = 2;
270 transferablesArgIndex = 1; 275 transferablesArgIndex = 1;
271 } 276 }
272 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, portArray, arrayBufferArray, exc eptionState)) { 277 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, portArray, arrayBufferArray, exc eptionState)) {
273 exceptionState.throwIfNeeded(); 278 exceptionState.throwIfNeeded();
274 return; 279 return;
275 } 280 }
276 } 281 }
277 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri gin, info[targetOriginArgIndex]); 282 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri gin, info[targetOriginArgIndex]);
278 283
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::curren t(isolate)); 547 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::curren t(isolate));
543 if (context.IsEmpty()) 548 if (context.IsEmpty())
544 return v8Undefined(); 549 return v8Undefined();
545 550
546 v8::Handle<v8::Object> global = context->Global(); 551 v8::Handle<v8::Object> global = context->Global();
547 ASSERT(!global.IsEmpty()); 552 ASSERT(!global.IsEmpty());
548 return global; 553 return global;
549 } 554 }
550 555
551 } // namespace blink 556 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/core/frame/UseCounter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698