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

Side by Side Diff: third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp

Issue 2122273002: Merge some repeated code in ImageBitmapFactories into a helper function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h ('k') | no next file » | 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) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 if (value.isBlob()) 79 if (value.isBlob())
80 return value.getAsBlob(); 80 return value.getAsBlob();
81 if (value.isImageData()) 81 if (value.isImageData())
82 return value.getAsImageData(); 82 return value.getAsImageData();
83 if (value.isImageBitmap()) 83 if (value.isImageBitmap())
84 return value.getAsImageBitmap(); 84 return value.getAsImageBitmap();
85 ASSERT_NOT_REACHED(); 85 ASSERT_NOT_REACHED();
86 return nullptr; 86 return nullptr;
87 } 87 }
88 88
89 ScriptPromise ImageBitmapFactories::createImageBitmapFromBlob(ScriptState* scrip tState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, const IntRect & cropRect, const ImageBitmapOptions& options)
90 {
91 Blob* blob = static_cast<Blob*>(bitmapSource);
92 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::create( from(eventTarget), cropRect, options, scriptState);
93 ScriptPromise promise = loader->promise();
94 from(eventTarget).addLoader(loader);
95 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob);
96 return promise;
97 }
98
89 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag eBitmapOptions& options, ExceptionState& exceptionState) 99 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, const Imag eBitmapOptions& options, ExceptionState& exceptionState)
90 { 100 {
91 UseCounter::Feature feature = UseCounter::CreateImageBitmap; 101 UseCounter::Feature feature = UseCounter::CreateImageBitmap;
92 UseCounter::count(scriptState->getExecutionContext(), feature); 102 UseCounter::count(scriptState->getExecutionContext(), feature);
93 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, false); 103 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, false);
94 if (!bitmapSourceInternal) 104 if (!bitmapSourceInternal)
95 return ScriptPromise(); 105 return ScriptPromise();
96 if (bitmapSourceInternal->isBlob()) { 106 if (bitmapSourceInternal->isBlob())
97 Blob* blob = static_cast<Blob*>(bitmapSourceInternal); 107 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSourceI nternal, IntRect(), options);
98 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre ate(from(eventTarget), IntRect(), options, scriptState);
99 ScriptPromise promise = loader->promise();
100 from(eventTarget).addLoader(loader);
101 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob);
102 return promise;
103 }
104 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize(); 108 IntSize srcSize = bitmapSourceInternal->bitmapSourceSize();
105 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), options, exceptionState); 109 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, 0, 0, srcSize.width(), srcSize.height(), options, exceptionState);
106 } 110 }
107 111
108 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in t sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& excepti onState) 112 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, const ImageBitmapSourceUnion& bitmapSource, int sx, in t sy, int sw, int sh, const ImageBitmapOptions& options, ExceptionState& excepti onState)
109 { 113 {
110 UseCounter::Feature feature = UseCounter::CreateImageBitmap; 114 UseCounter::Feature feature = UseCounter::CreateImageBitmap;
111 UseCounter::count(scriptState->getExecutionContext(), feature); 115 UseCounter::count(scriptState->getExecutionContext(), feature);
112 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, true); 116 ImageBitmapSource* bitmapSourceInternal = toImageBitmapSourceInternal(bitmap Source, exceptionState, true);
113 if (!bitmapSourceInternal) 117 if (!bitmapSourceInternal)
114 return ScriptPromise(); 118 return ScriptPromise();
115 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, options, exceptionState); 119 return createImageBitmap(scriptState, eventTarget, bitmapSourceInternal, sx, sy, sw, sh, options, exceptionState);
116 } 120 }
117 121
118 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState) 122 ScriptPromise ImageBitmapFactories::createImageBitmap(ScriptState* scriptState, EventTarget& eventTarget, ImageBitmapSource* bitmapSource, int sx, int sy, int s w, int sh, const ImageBitmapOptions& options, ExceptionState& exceptionState)
119 { 123 {
120 if (bitmapSource->isBlob()) { 124 if (bitmapSource->isBlob()) {
121 if (!sw || !sh) { 125 if (!sw || !sh) {
122 exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width")); 126 exceptionState.throwDOMException(IndexSizeError, String::format("The source %s provided is 0.", sw ? "height" : "width"));
123 return ScriptPromise(); 127 return ScriptPromise();
124 } 128 }
125 Blob* blob = static_cast<Blob*>(bitmapSource); 129 return createImageBitmapFromBlob(scriptState, eventTarget, bitmapSource, IntRect(sx, sy, sw, sh), options);
126 ImageBitmapLoader* loader = ImageBitmapFactories::ImageBitmapLoader::cre ate(from(eventTarget), IntRect(sx, sy, sw, sh), options, scriptState);
127 ScriptPromise promise = loader->promise();
128 from(eventTarget).addLoader(loader);
129 loader->loadBlobAsync(eventTarget.getExecutionContext(), blob);
130 return promise;
131 } 130 }
132 131
133 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, options, exceptionState); 132 return bitmapSource->createImageBitmap(scriptState, eventTarget, sx, sy, sw, sh, options, exceptionState);
134 } 133 }
135 134
136 const char* ImageBitmapFactories::supplementName() 135 const char* ImageBitmapFactories::supplementName()
137 { 136 {
138 return "ImageBitmapFactories"; 137 return "ImageBitmapFactories";
139 } 138 }
140 139
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 m_factory->didFinishLoading(this); 268 m_factory->didFinishLoading(this);
270 } 269 }
271 270
272 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) 271 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader)
273 { 272 {
274 visitor->trace(m_factory); 273 visitor->trace(m_factory);
275 visitor->trace(m_resolver); 274 visitor->trace(m_resolver);
276 } 275 }
277 276
278 } // namespace blink 277 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698