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

Side by Side Diff: webkit/glue/webframe_impl.cc

Issue 164225: Switch to WebFrame from the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webframe_impl.h ('k') | webkit/glue/webframe_unittest.cc » ('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) 2006 Samuel Weinig (sam.weinig@gmail.com) 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 #include "base/message_loop.h" 141 #include "base/message_loop.h"
142 #include "base/stats_counters.h" 142 #include "base/stats_counters.h"
143 #include "base/string_util.h" 143 #include "base/string_util.h"
144 #include "net/base/net_errors.h" 144 #include "net/base/net_errors.h"
145 #include "skia/ext/bitmap_platform_device.h" 145 #include "skia/ext/bitmap_platform_device.h"
146 #include "skia/ext/platform_canvas.h" 146 #include "skia/ext/platform_canvas.h"
147 #include "webkit/api/public/WebConsoleMessage.h" 147 #include "webkit/api/public/WebConsoleMessage.h"
148 #include "webkit/api/public/WebFindOptions.h" 148 #include "webkit/api/public/WebFindOptions.h"
149 #include "webkit/api/public/WebForm.h" 149 #include "webkit/api/public/WebForm.h"
150 #include "webkit/api/public/WebHistoryItem.h" 150 #include "webkit/api/public/WebHistoryItem.h"
151 #include "webkit/api/public/WebRange.h"
151 #include "webkit/api/public/WebRect.h" 152 #include "webkit/api/public/WebRect.h"
152 #include "webkit/api/public/WebScriptSource.h" 153 #include "webkit/api/public/WebScriptSource.h"
153 #include "webkit/api/public/WebSize.h" 154 #include "webkit/api/public/WebSize.h"
154 #include "webkit/api/public/WebURLError.h" 155 #include "webkit/api/public/WebURLError.h"
156 #include "webkit/api/public/WebVector.h"
155 #include "webkit/glue/chrome_client_impl.h" 157 #include "webkit/glue/chrome_client_impl.h"
156 #include "webkit/glue/dom_operations.h" 158 #include "webkit/glue/dom_operations.h"
157 #include "webkit/glue/dom_operations_private.h" 159 #include "webkit/glue/dom_operations_private.h"
158 #include "webkit/glue/glue_util.h" 160 #include "webkit/glue/glue_util.h"
159 #include "webkit/glue/webdatasource_impl.h" 161 #include "webkit/glue/webdatasource_impl.h"
160 #include "webkit/glue/webframe_impl.h" 162 #include "webkit/glue/webframe_impl.h"
161 #include "webkit/glue/webtextinput_impl.h"
162 #include "webkit/glue/webview_impl.h" 163 #include "webkit/glue/webview_impl.h"
163 164
164 #if defined(OS_LINUX) 165 #if defined(OS_LINUX)
165 #include <gdk/gdk.h> 166 #include <gdk/gdk.h>
166 #endif 167 #endif
167 168
168 #if USE(JSC) 169 #if USE(JSC)
169 #include "bridge/c/c_instance.h" 170 #include "bridge/c/c_instance.h"
170 #include "bridge/runtime_object.h" 171 #include "bridge/runtime_object.h"
171 #endif 172 #endif
172 173
173 using base::Time; 174 using base::Time;
174 175
176 using WebCore::AtomicString;
175 using WebCore::ChromeClientChromium; 177 using WebCore::ChromeClientChromium;
176 using WebCore::Color; 178 using WebCore::Color;
177 using WebCore::Document; 179 using WebCore::Document;
178 using WebCore::DocumentFragment; 180 using WebCore::DocumentFragment;
179 using WebCore::DocumentLoader; 181 using WebCore::DocumentLoader;
180 using WebCore::ExceptionCode; 182 using WebCore::ExceptionCode;
181 using WebCore::GraphicsContext; 183 using WebCore::GraphicsContext;
182 using WebCore::HTMLFrameOwnerElement; 184 using WebCore::HTMLFrameOwnerElement;
183 using WebCore::Frame; 185 using WebCore::Frame;
184 using WebCore::FrameLoader; 186 using WebCore::FrameLoader;
(...skipping 21 matching lines...) Expand all
206 using WebCore::SubstituteData; 208 using WebCore::SubstituteData;
207 using WebCore::TextIterator; 209 using WebCore::TextIterator;
208 using WebCore::VisiblePosition; 210 using WebCore::VisiblePosition;
209 using WebCore::XPathResult; 211 using WebCore::XPathResult;
210 212
211 using WebKit::WebCanvas; 213 using WebKit::WebCanvas;
212 using WebKit::WebConsoleMessage; 214 using WebKit::WebConsoleMessage;
213 using WebKit::WebData; 215 using WebKit::WebData;
214 using WebKit::WebDataSource; 216 using WebKit::WebDataSource;
215 using WebKit::WebFindOptions; 217 using WebKit::WebFindOptions;
218 using WebKit::WebFrame;
216 using WebKit::WebHistoryItem; 219 using WebKit::WebHistoryItem;
217 using WebKit::WebForm; 220 using WebKit::WebForm;
221 using WebKit::WebRange;
218 using WebKit::WebRect; 222 using WebKit::WebRect;
219 using WebKit::WebScriptSource; 223 using WebKit::WebScriptSource;
220 using WebKit::WebSize; 224 using WebKit::WebSize;
221 using WebKit::WebString; 225 using WebKit::WebString;
222 using WebKit::WebURL; 226 using WebKit::WebURL;
223 using WebKit::WebURLError; 227 using WebKit::WebURLError;
224 using WebKit::WebURLRequest; 228 using WebKit::WebURLRequest;
225 using WebKit::WebURLResponse; 229 using WebKit::WebURLResponse;
230 using WebKit::WebVector;
226 231
227 // Key for a StatsCounter tracking how many WebFrames are active. 232 // Key for a StatsCounter tracking how many WebFrames are active.
228 static const char* const kWebFrameActiveCount = "WebFrameActiveCount"; 233 static const char* const kWebFrameActiveCount = "WebFrameActiveCount";
229 234
230 static const char* const kOSDType = "application/opensearchdescription+xml"; 235 static const char* const kOSDType = "application/opensearchdescription+xml";
231 static const char* const kOSDRel = "search"; 236 static const char* const kOSDRel = "search";
232 237
233 // The separator between frames when the frames are converted to plain text. 238 // The separator between frames when the frames are converted to plain text.
234 static const wchar_t kFrameSeparator[] = L"\n\n"; 239 static const wchar_t kFrameSeparator[] = L"\n\n";
235 static const int kFrameSeparatorLen = arraysize(kFrameSeparator) - 1; 240 static const size_t kFrameSeparatorLen = arraysize(kFrameSeparator) - 1;
236 241
237 // Backend for GetContentAsPlainText, this is a recursive function that gets 242 // Backend for contentAsPlainText, this is a recursive function that gets
238 // the text for the current frame and all of its subframes. It will append 243 // the text for the current frame and all of its subframes. It will append
239 // the text of each frame in turn to the |output| up to |max_chars| length. 244 // the text of each frame in turn to the |output| up to |max_chars| length.
240 // 245 //
241 // The |frame| must be non-NULL. 246 // The |frame| must be non-NULL.
242 static void FrameContentAsPlainText(int max_chars, Frame* frame, 247 static void FrameContentAsPlainText(size_t max_chars, Frame* frame,
243 std::wstring* output) { 248 std::wstring* output) {
244 Document* doc = frame->document(); 249 Document* doc = frame->document();
245 if (!doc) 250 if (!doc)
246 return; 251 return;
247 252
248 if (!frame->view()) 253 if (!frame->view())
249 return; 254 return;
250 255
251 // TextIterator iterates over the visual representation of the DOM. As such, 256 // TextIterator iterates over the visual representation of the DOM. As such,
252 // it requires you to do a layout before using it (otherwise it'll crash). 257 // it requires you to do a layout before using it (otherwise it'll crash).
(...skipping 25 matching lines...) Expand all
278 // currently understand the conditions for this to occur. Ideally, the 283 // currently understand the conditions for this to occur. Ideally, the
279 // iterators would never get into the condition so we should fix them 284 // iterators would never get into the condition so we should fix them
280 // if we can. 285 // if we can.
281 NOTREACHED(); 286 NOTREACHED();
282 break; 287 break;
283 } 288 }
284 289
285 // Just got a NULL node, we can forge ahead! 290 // Just got a NULL node, we can forge ahead!
286 continue; 291 continue;
287 } 292 }
288 int to_append = std::min(it.length(), 293 size_t to_append = std::min(static_cast<size_t>(it.length()),
289 max_chars - static_cast<int>(output->size())); 294 max_chars - output->size());
290 std::wstring wstr; 295 std::wstring wstr;
291 UTF16ToWide(reinterpret_cast<const char16*>(chars), to_append, &wstr); 296 UTF16ToWide(reinterpret_cast<const char16*>(chars), to_append, &wstr);
292 output->append(wstr.c_str(), to_append); 297 output->append(wstr.c_str(), to_append);
293 if (output->size() >= static_cast<size_t>(max_chars)) 298 if (output->size() >= max_chars)
294 return; // Filled up the buffer. 299 return; // Filled up the buffer.
295 } 300 }
296 } 301 }
297 302
298 // Recursively walk the children. 303 // Recursively walk the children.
299 FrameTree* frame_tree = frame->tree(); 304 FrameTree* frame_tree = frame->tree();
300 for (Frame* cur_child = frame_tree->firstChild(); cur_child; 305 for (Frame* cur_child = frame_tree->firstChild(); cur_child;
301 cur_child = cur_child->tree()->nextSibling()) { 306 cur_child = cur_child->tree()->nextSibling()) {
302 // Make sure the frame separator won't fill up the buffer, and give up if 307 // Make sure the frame separator won't fill up the buffer, and give up if
303 // it will. The danger is if the separator will make the buffer longer than 308 // it will. The danger is if the separator will make the buffer longer than
304 // max_chars. This will cause the computation above: 309 // max_chars. This will cause the computation above:
305 // max_chars - output->size() 310 // max_chars - output->size()
306 // to be a negative number which will crash when the subframe is added. 311 // to be a negative number which will crash when the subframe is added.
307 if (static_cast<int>(output->size()) >= max_chars - kFrameSeparatorLen) 312 if (output->size() >= max_chars - kFrameSeparatorLen)
308 return; 313 return;
309 314
310 output->append(kFrameSeparator, kFrameSeparatorLen); 315 output->append(kFrameSeparator, kFrameSeparatorLen);
311 FrameContentAsPlainText(max_chars, cur_child, output); 316 FrameContentAsPlainText(max_chars, cur_child, output);
312 if (output->size() >= static_cast<size_t>(max_chars)) 317 if (output->size() >= max_chars)
313 return; // Filled up the buffer. 318 return; // Filled up the buffer.
314 } 319 }
315 } 320 }
316 321
317 // Simple class to override some of PrintContext behavior. 322 // Simple class to override some of PrintContext behavior.
318 class ChromePrintContext : public WebCore::PrintContext { 323 class ChromePrintContext : public WebCore::PrintContext {
319 public: 324 public:
320 ChromePrintContext(Frame* frame) 325 ChromePrintContext(Frame* frame)
321 : PrintContext(frame), 326 : PrintContext(frame),
322 printed_page_width_(0) { 327 printed_page_width_(0) {
(...skipping 29 matching lines...) Expand all
352 357
353 private: 358 private:
354 DISALLOW_COPY_AND_ASSIGN(ChromePrintContext); 359 DISALLOW_COPY_AND_ASSIGN(ChromePrintContext);
355 }; 360 };
356 361
357 // WebFrameImpl ---------------------------------------------------------------- 362 // WebFrameImpl ----------------------------------------------------------------
358 363
359 int WebFrameImpl::live_object_count_ = 0; 364 int WebFrameImpl::live_object_count_ = 0;
360 365
361 // static 366 // static
362 WebFrame* WebFrame::RetrieveFrameForEnteredContext() { 367 WebFrame* WebFrame::frameForEnteredContext() {
363 WebCore::Frame* frame = 368 Frame* frame =
364 WebCore::ScriptController::retrieveFrameForEnteredContext(); 369 WebCore::ScriptController::retrieveFrameForEnteredContext();
365 if (frame) 370 if (frame)
366 return WebFrameImpl::FromFrame(frame); 371 return WebFrameImpl::FromFrame(frame);
367 else 372 else
368 return NULL; 373 return NULL;
369 } 374 }
370 375
371 // static 376 // static
372 WebFrame* WebFrame::RetrieveFrameForCurrentContext() { 377 WebFrame* WebFrame::frameForCurrentContext() {
373 WebCore::Frame* frame = 378 Frame* frame =
374 WebCore::ScriptController::retrieveFrameForCurrentContext(); 379 WebCore::ScriptController::retrieveFrameForCurrentContext();
375 if (frame) 380 if (frame)
376 return WebFrameImpl::FromFrame(frame); 381 return WebFrameImpl::FromFrame(frame);
377 else 382 else
378 return NULL; 383 return NULL;
379 } 384 }
380 385
381 WebFrameImpl::WebFrameImpl() 386 WebFrameImpl::WebFrameImpl()
382 : ALLOW_THIS_IN_INITIALIZER_LIST(frame_loader_client_(this)), 387 : ALLOW_THIS_IN_INITIALIZER_LIST(frame_loader_client_(this)),
383 ALLOW_THIS_IN_INITIALIZER_LIST(scope_matches_factory_(this)), 388 ALLOW_THIS_IN_INITIALIZER_LIST(scope_matches_factory_(this)),
384 plugin_delegate_(NULL), 389 plugin_delegate_(NULL),
385 active_match_frame_(NULL), 390 active_match_frame_(NULL),
386 active_match_index_(-1), 391 active_match_index_(-1),
387 locating_active_rect_(false), 392 locating_active_rect_(false),
388 resume_scoping_from_range_(NULL), 393 resume_scoping_from_range_(NULL),
389 last_match_count_(-1), 394 last_match_count_(-1),
390 total_matchcount_(-1), 395 total_matchcount_(-1),
391 frames_scoping_count_(-1), 396 frames_scoping_count_(-1),
392 scoping_complete_(false), 397 scoping_complete_(false),
393 next_invalidate_after_(0) { 398 next_invalidate_after_(0) {
394 StatsCounter(kWebFrameActiveCount).Increment(); 399 StatsCounter(kWebFrameActiveCount).Increment();
395 live_object_count_++; 400 live_object_count_++;
396 } 401 }
397 402
398 WebFrameImpl::~WebFrameImpl() { 403 WebFrameImpl::~WebFrameImpl() {
399 StatsCounter(kWebFrameActiveCount).Decrement(); 404 StatsCounter(kWebFrameActiveCount).Decrement();
400 live_object_count_--; 405 live_object_count_--;
401 406
402 CancelPendingScopingEffort(); 407 cancelPendingScopingEffort();
403 ClearPasswordListeners(); 408 ClearPasswordListeners();
404 } 409 }
405 410
406 // WebFrame ------------------------------------------------------------------- 411 // WebFrame -------------------------------------------------------------------
407 412
408 void WebFrameImpl::InitMainFrame(WebViewImpl* webview_impl) { 413 void WebFrameImpl::InitMainFrame(WebViewImpl* webview_impl) {
409 RefPtr<Frame> frame = 414 RefPtr<Frame> frame =
410 Frame::create(webview_impl->page(), 0, &frame_loader_client_); 415 Frame::create(webview_impl->page(), 0, &frame_loader_client_);
411 frame_ = frame.get(); 416 frame_ = frame.get();
412 417
413 // Add reference on behalf of FrameLoader. See comments in 418 // Add reference on behalf of FrameLoader. See comments in
414 // WebFrameLoaderClient::frameLoaderDestroyed for more info. 419 // WebFrameLoaderClient::frameLoaderDestroyed for more info.
415 AddRef(); 420 AddRef();
416 421
417 // We must call init() after frame_ is assigned because it is referenced 422 // We must call init() after frame_ is assigned because it is referenced
418 // during init(). 423 // during init().
419 frame_->init(); 424 frame_->init();
420 } 425 }
421 426
422 void WebFrameImpl::Reload() { 427 void WebFrameImpl::reload() {
423 frame_->loader()->saveDocumentAndScrollState(); 428 frame_->loader()->saveDocumentAndScrollState();
424 429
425 StopLoading(); // Make sure existing activity stops. 430 stopLoading(); // Make sure existing activity stops.
426 frame_->loader()->reload(); 431 frame_->loader()->reload();
427 } 432 }
428 433
429 void WebFrameImpl::LoadRequest(const WebURLRequest& request) { 434 void WebFrameImpl::loadRequest(const WebURLRequest& request) {
430 const ResourceRequest* resource_request = 435 const ResourceRequest* resource_request =
431 webkit_glue::WebURLRequestToResourceRequest(&request); 436 webkit_glue::WebURLRequestToResourceRequest(&request);
432 DCHECK(resource_request); 437 DCHECK(resource_request);
433 438
434 if (resource_request->url().protocolIs("javascript")) { 439 if (resource_request->url().protocolIs("javascript")) {
435 LoadJavaScriptURL(resource_request->url()); 440 LoadJavaScriptURL(resource_request->url());
436 return; 441 return;
437 } 442 }
438 443
439 StopLoading(); // Make sure existing activity stops. 444 stopLoading(); // Make sure existing activity stops.
440 frame_->loader()->load(*resource_request, false); 445 frame_->loader()->load(*resource_request, false);
441 } 446 }
442 447
443 void WebFrameImpl::LoadHistoryItem(const WebHistoryItem& item) { 448 void WebFrameImpl::loadHistoryItem(const WebHistoryItem& item) {
444 RefPtr<HistoryItem> history_item = 449 RefPtr<HistoryItem> history_item =
445 webkit_glue::WebHistoryItemToHistoryItem(item); 450 webkit_glue::WebHistoryItemToHistoryItem(item);
446 DCHECK(history_item.get()); 451 DCHECK(history_item.get());
447 452
448 StopLoading(); // Make sure existing activity stops. 453 stopLoading(); // Make sure existing activity stops.
449 454
450 // If there is no current_item, which happens when we are navigating in 455 // If there is no current_item, which happens when we are navigating in
451 // session history after a crash, we need to manufacture one otherwise WebKit 456 // session history after a crash, we need to manufacture one otherwise WebKit
452 // hoarks. This is probably the wrong thing to do, but it seems to work. 457 // hoarks. This is probably the wrong thing to do, but it seems to work.
453 RefPtr<HistoryItem> current_item = frame_->loader()->currentHistoryItem(); 458 RefPtr<HistoryItem> current_item = frame_->loader()->currentHistoryItem();
454 if (!current_item) { 459 if (!current_item) {
455 current_item = HistoryItem::create(); 460 current_item = HistoryItem::create();
456 current_item->setLastVisitWasFailure(true); 461 current_item->setLastVisitWasFailure(true);
457 frame_->loader()->setCurrentHistoryItem(current_item); 462 frame_->loader()->setCurrentHistoryItem(current_item);
458 GetWebViewImpl()->SetCurrentHistoryItem(current_item.get()); 463 GetWebViewImpl()->SetCurrentHistoryItem(current_item.get());
459 } 464 }
460 465
461 frame_->loader()->goToItem(history_item.get(), 466 frame_->loader()->goToItem(history_item.get(),
462 WebCore::FrameLoadTypeIndexedBackForward); 467 WebCore::FrameLoadTypeIndexedBackForward);
463 } 468 }
464 469
465 void WebFrameImpl::LoadData(const WebData& data, 470 void WebFrameImpl::loadData(const WebData& data,
466 const WebString& mime_type, 471 const WebString& mime_type,
467 const WebString& text_encoding, 472 const WebString& text_encoding,
468 const WebURL& base_url, 473 const WebURL& base_url,
469 const WebURL& unreachable_url, 474 const WebURL& unreachable_url,
470 bool replace) { 475 bool replace) {
471 SubstituteData subst_data( 476 SubstituteData subst_data(
472 webkit_glue::WebDataToSharedBuffer(data), 477 webkit_glue::WebDataToSharedBuffer(data),
473 webkit_glue::WebStringToString(mime_type), 478 webkit_glue::WebStringToString(mime_type),
474 webkit_glue::WebStringToString(text_encoding), 479 webkit_glue::WebStringToString(text_encoding),
475 webkit_glue::WebURLToKURL(unreachable_url)); 480 webkit_glue::WebURLToKURL(unreachable_url));
476 DCHECK(subst_data.isValid()); 481 DCHECK(subst_data.isValid());
477 482
478 StopLoading(); // Make sure existing activity stops. 483 stopLoading(); // Make sure existing activity stops.
479 frame_->loader()->load(ResourceRequest(webkit_glue::WebURLToKURL(base_url)), 484 frame_->loader()->load(ResourceRequest(webkit_glue::WebURLToKURL(base_url)),
480 subst_data, false); 485 subst_data, false);
481 if (replace) { 486 if (replace) {
482 // Do this to force WebKit to treat the load as replacing the currently 487 // Do this to force WebKit to treat the load as replacing the currently
483 // loaded page. 488 // loaded page.
484 frame_->loader()->setReplacing(); 489 frame_->loader()->setReplacing();
485 } 490 }
486 } 491 }
487 492
488 void WebFrameImpl::LoadHTMLString(const WebData& data, 493 void WebFrameImpl::loadHTMLString(const WebData& data,
489 const WebURL& base_url, 494 const WebURL& base_url,
490 const WebURL& unreachable_url, 495 const WebURL& unreachable_url,
491 bool replace) { 496 bool replace) {
492 LoadData(data, 497 loadData(data,
493 WebString::fromUTF8("text/html"), 498 WebString::fromUTF8("text/html"),
494 WebString::fromUTF8("UTF-8"), 499 WebString::fromUTF8("UTF-8"),
495 base_url, 500 base_url,
496 unreachable_url, 501 unreachable_url,
497 replace); 502 replace);
498 } 503 }
499 504
500 GURL WebFrameImpl::GetURL() const { 505 WebURL WebFrameImpl::url() const {
501 const WebDataSource* ds = GetDataSource(); 506 const WebDataSource* ds = dataSource();
502 if (!ds) 507 if (!ds)
503 return GURL(); 508 return WebURL();
504 return ds->request().url(); 509 return ds->request().url();
505 } 510 }
506 511
507 GURL WebFrameImpl::GetFavIconURL() const { 512 WebURL WebFrameImpl::favIconURL() const {
508 WebCore::FrameLoader* frame_loader = frame_->loader(); 513 WebCore::FrameLoader* frame_loader = frame_->loader();
509 // The URL to the favicon may be in the header. As such, only 514 // The URL to the favicon may be in the header. As such, only
510 // ask the loader for the favicon if it's finished loading. 515 // ask the loader for the favicon if it's finished loading.
511 if (frame_loader->state() == WebCore::FrameStateComplete) { 516 if (frame_loader->state() == WebCore::FrameStateComplete) {
512 const KURL& url = frame_loader->iconURL(); 517 const KURL& url = frame_loader->iconURL();
513 if (!url.isEmpty()) { 518 if (!url.isEmpty()) {
514 return webkit_glue::KURLToGURL(url); 519 return webkit_glue::KURLToWebURL(url);
515 } 520 }
516 } 521 }
517 return GURL(); 522 return WebURL();
518 } 523 }
519 524
520 GURL WebFrameImpl::GetOSDDURL() const { 525 WebURL WebFrameImpl::openSearchDescriptionURL() const {
521 WebCore::FrameLoader* frame_loader = frame_->loader(); 526 WebCore::FrameLoader* frame_loader = frame_->loader();
522 if (frame_loader->state() == WebCore::FrameStateComplete && 527 if (frame_loader->state() == WebCore::FrameStateComplete &&
523 frame_->document() && frame_->document()->head() && 528 frame_->document() && frame_->document()->head() &&
524 !frame_->tree()->parent()) { 529 !frame_->tree()->parent()) {
525 WebCore::HTMLHeadElement* head = frame_->document()->head(); 530 WebCore::HTMLHeadElement* head = frame_->document()->head();
526 if (head) { 531 if (head) {
527 RefPtr<WebCore::HTMLCollection> children = head->children(); 532 RefPtr<WebCore::HTMLCollection> children = head->children();
528 for (Node* child = children->firstItem(); child != NULL; 533 for (Node* child = children->firstItem(); child != NULL;
529 child = children->nextItem()) { 534 child = children->nextItem()) {
530 WebCore::HTMLLinkElement* link_element = 535 WebCore::HTMLLinkElement* link_element =
531 webkit_glue::CastToHTMLLinkElement(child); 536 webkit_glue::CastToHTMLLinkElement(child);
532 if (link_element && link_element->type() == kOSDType && 537 if (link_element && link_element->type() == kOSDType &&
533 link_element->rel() == kOSDRel && !link_element->href().isEmpty()) { 538 link_element->rel() == kOSDRel && !link_element->href().isEmpty()) {
534 return webkit_glue::KURLToGURL(link_element->href()); 539 return webkit_glue::KURLToWebURL(link_element->href());
535 } 540 }
536 } 541 }
537 } 542 }
538 } 543 }
539 return GURL(); 544 return WebURL();
540 } 545 }
541 546
542 int WebFrameImpl::GetContentsPreferredWidth() const { 547 int WebFrameImpl::contentsPreferredWidth() const {
543 if ((frame_->document() != NULL) && 548 if ((frame_->document() != NULL) &&
544 (frame_->document()->renderView() != NULL)) { 549 (frame_->document()->renderView() != NULL)) {
545 return frame_->document()->renderView()->minPrefWidth(); 550 return frame_->document()->renderView()->minPrefWidth();
546 } else { 551 } else {
547 return 0; 552 return 0;
548 } 553 }
549 } 554 }
550 555
551 WebHistoryItem WebFrameImpl::GetPreviousHistoryItem() const { 556 WebHistoryItem WebFrameImpl::previousHistoryItem() const {
552 // We use the previous item here because documentState (filled-out forms) 557 // We use the previous item here because documentState (filled-out forms)
553 // only get saved to history when it becomes the previous item. The caller 558 // only get saved to history when it becomes the previous item. The caller
554 // is expected to query the history item after a navigation occurs, after 559 // is expected to query the history item after a navigation occurs, after
555 // the desired history item has become the previous entry. 560 // the desired history item has become the previous entry.
556 return webkit_glue::HistoryItemToWebHistoryItem( 561 return webkit_glue::HistoryItemToWebHistoryItem(
557 GetWebViewImpl()->GetPreviousHistoryItem()); 562 GetWebViewImpl()->GetPreviousHistoryItem());
558 } 563 }
559 564
560 WebHistoryItem WebFrameImpl::GetCurrentHistoryItem() const { 565 WebHistoryItem WebFrameImpl::currentHistoryItem() const {
561 frame_->loader()->saveDocumentAndScrollState(); 566 frame_->loader()->saveDocumentAndScrollState();
562 567
563 return webkit_glue::HistoryItemToWebHistoryItem( 568 return webkit_glue::HistoryItemToWebHistoryItem(
564 frame_->page()->backForwardList()->currentItem()); 569 frame_->page()->backForwardList()->currentItem());
565 } 570 }
566 571
567 static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader) { 572 static WebDataSource* DataSourceForDocLoader(DocumentLoader* loader) {
568 return loader ? WebDataSourceImpl::FromLoader(loader) : NULL; 573 return loader ? WebDataSourceImpl::FromLoader(loader) : NULL;
569 } 574 }
570 575
571 WebDataSource* WebFrameImpl::GetDataSource() const { 576 WebDataSource* WebFrameImpl::dataSource() const {
572 return DataSourceForDocLoader(frame_->loader()->documentLoader()); 577 return DataSourceForDocLoader(frame_->loader()->documentLoader());
573 } 578 }
574 579
575 WebDataSourceImpl* WebFrameImpl::GetDataSourceImpl() const { 580 WebDataSourceImpl* WebFrameImpl::GetDataSourceImpl() const {
576 return static_cast<WebDataSourceImpl*>(GetDataSource()); 581 return static_cast<WebDataSourceImpl*>(dataSource());
577 } 582 }
578 583
579 WebDataSource* WebFrameImpl::GetProvisionalDataSource() const { 584 WebDataSource* WebFrameImpl::provisionalDataSource() const {
580 FrameLoader* frame_loader = frame_->loader(); 585 FrameLoader* frame_loader = frame_->loader();
581 586
582 // We regard the policy document loader as still provisional. 587 // We regard the policy document loader as still provisional.
583 DocumentLoader* doc_loader = frame_loader->provisionalDocumentLoader(); 588 DocumentLoader* doc_loader = frame_loader->provisionalDocumentLoader();
584 if (!doc_loader) 589 if (!doc_loader)
585 doc_loader = frame_loader->policyDocumentLoader(); 590 doc_loader = frame_loader->policyDocumentLoader();
586 591
587 return DataSourceForDocLoader(doc_loader); 592 return DataSourceForDocLoader(doc_loader);
588 } 593 }
589 594
590 WebDataSourceImpl* WebFrameImpl::GetProvisionalDataSourceImpl() const { 595 WebDataSourceImpl* WebFrameImpl::GetProvisionalDataSourceImpl() const {
591 return static_cast<WebDataSourceImpl*>(GetProvisionalDataSource()); 596 return static_cast<WebDataSourceImpl*>(provisionalDataSource());
592 } 597 }
593 598
594 void WebFrameImpl::StopLoading() { 599 void WebFrameImpl::stopLoading() {
595 if (!frame_) 600 if (!frame_)
596 return; 601 return;
597 602
598 // TODO(darin): Figure out what we should really do here. It seems like a 603 // TODO(darin): Figure out what we should really do here. It seems like a
599 // bug that FrameLoader::stopLoading doesn't call stopAllLoaders. 604 // bug that FrameLoader::stopLoading doesn't call stopAllLoaders.
600 frame_->loader()->stopAllLoaders(); 605 frame_->loader()->stopAllLoaders();
601 frame_->loader()->stopLoading(false); 606 frame_->loader()->stopLoading(false);
602 } 607 }
603 608
604 bool WebFrameImpl::IsLoading() const { 609 bool WebFrameImpl::isLoading() const {
605 if (!frame_) 610 if (!frame_)
606 return false; 611 return false;
607 return frame_->loader()->isLoading(); 612 return frame_->loader()->isLoading();
608 } 613 }
609 614
610 WebFrame* WebFrameImpl::GetOpener() const { 615 WebFrame* WebFrameImpl::opener() const {
611 if (frame_) { 616 if (frame_) {
612 Frame* opener = frame_->loader()->opener(); 617 Frame* opener = frame_->loader()->opener();
613 if (opener) 618 if (opener)
614 return FromFrame(opener); 619 return FromFrame(opener);
615 } 620 }
616 return NULL; 621 return NULL;
617 } 622 }
618 623
619 WebFrame* WebFrameImpl::GetParent() const { 624 WebFrame* WebFrameImpl::parent() const {
620 if (frame_) { 625 if (frame_) {
621 Frame *parent = frame_->tree()->parent(); 626 Frame *parent = frame_->tree()->parent();
622 if (parent) 627 if (parent)
623 return FromFrame(parent); 628 return FromFrame(parent);
624 } 629 }
625 return NULL; 630 return NULL;
626 } 631 }
627 632
628 WebFrame* WebFrameImpl::GetTop() const { 633 WebFrame* WebFrameImpl::top() const {
629 if (frame_) 634 if (frame_)
630 return FromFrame(frame_->tree()->top()); 635 return FromFrame(frame_->tree()->top());
631 636
632 return NULL; 637 return NULL;
633 } 638 }
634 639
635 WebFrame* WebFrameImpl::GetChildFrame(const std::wstring& xpath) const { 640 void WebFrameImpl::enableViewSourceMode(bool enable) {
636 // xpath string can represent a frame deep down the tree (across multiple
637 // frame DOMs).
638 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
639 // should break into 2 xpaths
640 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
641
642 if (xpath.empty())
643 return NULL;
644
645 std::wstring secondary;
646 String xpath_str;
647
648 std::wstring::size_type delim_pos = xpath.find_first_of(L'\n');
649 if (delim_pos != std::wstring::npos) {
650 std::wstring primary = xpath.substr(0, delim_pos);
651 secondary = xpath.substr(delim_pos + 1);
652 xpath_str = webkit_glue::StdWStringToString(primary);
653 } else {
654 xpath_str = webkit_glue::StdWStringToString(xpath);
655 }
656
657 Document* document = frame_->document();
658
659 ExceptionCode ec = 0;
660 PassRefPtr<XPathResult> xpath_result =
661 document->evaluate(xpath_str,
662 document,
663 NULL, /* namespace */
664 XPathResult::ORDERED_NODE_ITERATOR_TYPE,
665 NULL, /* XPathResult object */
666 ec);
667
668 if (!xpath_result.get())
669 return NULL;
670
671 Node* node = xpath_result->iterateNext(ec);
672
673 if (!node || !node->isFrameOwnerElement())
674 return NULL;
675 HTMLFrameOwnerElement* frame_element =
676 static_cast<HTMLFrameOwnerElement*>(node);
677 WebFrame* web_frame = FromFrame(frame_element->contentFrame());
678
679 if (secondary.empty())
680 return web_frame;
681 else
682 return web_frame->GetChildFrame(secondary);
683 }
684
685 void WebFrameImpl::SetInViewSourceMode(bool enable) {
686 if (frame_) 641 if (frame_)
687 frame_->setInViewSourceMode(enable); 642 frame_->setInViewSourceMode(enable);
688 } 643 }
689 644
690 bool WebFrameImpl::GetInViewSourceMode() const { 645 bool WebFrameImpl::isViewSourceModeEnabled() const {
691 if (frame_) 646 if (frame_)
692 return frame_->inViewSourceMode(); 647 return frame_->inViewSourceMode();
693 648
694 return false; 649 return false;
695 } 650 }
696 651
697 WebView* WebFrameImpl::GetView() const { 652 WebView* WebFrameImpl::view() const {
698 return GetWebViewImpl(); 653 return GetWebViewImpl();
699 } 654 }
700 655
701 void WebFrameImpl::GetForms(std::vector<WebForm>* results) const { 656 void WebFrameImpl::forms(WebVector<WebForm>& results) const {
702 results->clear();
703 if (!frame_) 657 if (!frame_)
704 return; 658 return;
659
705 RefPtr<WebCore::HTMLCollection> forms = frame_->document()->forms(); 660 RefPtr<WebCore::HTMLCollection> forms = frame_->document()->forms();
706 unsigned int form_count = forms->length(); 661 size_t form_count = forms->length();
707 for (unsigned int i = 0; i < form_count; ++i) { 662
663 WebVector<WebForm> temp(form_count);
664 for (size_t i = 0; i < form_count; ++i) {
708 Node* node = forms->item(i); 665 Node* node = forms->item(i);
709 // Strange but true, sometimes item can be NULL. 666 // Strange but true, sometimes item can be NULL.
710 if (node) { 667 if (node) {
711 results->push_back(webkit_glue::HTMLFormElementToWebForm( 668 temp[i] = webkit_glue::HTMLFormElementToWebForm(
712 static_cast<HTMLFormElement*>(node))); 669 static_cast<HTMLFormElement*>(node));
713 } 670 }
714 } 671 }
672 results.swap(temp);
715 } 673 }
716 674
717 std::string WebFrameImpl::GetSecurityOrigin() const { 675 WebString WebFrameImpl::securityOrigin() const {
718 if (frame_) { 676 if (frame_) {
719 if (frame_->document()) 677 if (frame_->document())
720 return webkit_glue::StringToStdString( 678 return webkit_glue::StringToWebString(
721 frame_->document()->securityOrigin()->toString()); 679 frame_->document()->securityOrigin()->toString());
722 } 680 }
723 return "null"; 681 return WebString::fromUTF8("null");
724 } 682 }
725 683
726 void WebFrameImpl::BindToWindowObject(const std::wstring& name, 684 void WebFrameImpl::bindToWindowObject(const WebString& name,
727 NPObject* object) { 685 NPObject* object) {
728 assert(frame_); 686 DCHECK(frame_);
729 if (!frame_ || !frame_->script()->isEnabled()) 687 if (!frame_ || !frame_->script()->isEnabled())
730 return; 688 return;
731 689
732 // TODO(mbelshe): Move this to the ScriptController and make it JS neutral. 690 // TODO(mbelshe): Move this to the ScriptController and make it JS neutral.
733 691
734 String key = webkit_glue::StdWStringToString(name); 692 String key = webkit_glue::WebStringToString(name);
735 #if USE(V8) 693 #if USE(V8)
736 frame_->script()->bindToWindowObject(frame_, key, object); 694 frame_->script()->bindToWindowObject(frame_, key, object);
737 #endif 695 #endif
738 696
739 #if USE(JSC) 697 #if USE(JSC)
740 JSC::JSGlobalObject* window = frame_->script()->globalObject(); 698 JSC::JSGlobalObject* window = frame_->script()->globalObject();
741 JSC::ExecState* exec = window->globalExec(); 699 JSC::ExecState* exec = window->globalExec();
742 JSC::Bindings::RootObject* root = frame_->script()->bindingRootObject(); 700 JSC::Bindings::RootObject* root = frame_->script()->bindingRootObject();
743 ASSERT(exec); 701 ASSERT(exec);
744 JSC::RuntimeObjectImp* instance(JSC::Bindings::Instance::createRuntimeObject( 702 JSC::RuntimeObjectImp* instance(JSC::Bindings::Instance::createRuntimeObject(
745 exec, JSC::Bindings::CInstance::create(object, root))); 703 exec, JSC::Bindings::CInstance::create(object, root)));
746 JSC::Identifier id(exec, key.latin1().data()); 704 JSC::Identifier id(exec, key.latin1().data());
747 JSC::PutPropertySlot slot; 705 JSC::PutPropertySlot slot;
748 window->put(exec, id, instance, slot); 706 window->put(exec, id, instance, slot);
749 #endif 707 #endif
750 } 708 }
751 709
752 710
753 // Call JavaScript garbage collection. 711 // Call JavaScript garbage collection.
754 void WebFrameImpl::CallJSGC() { 712 void WebFrameImpl::collectGarbage() {
755 if (!frame_) 713 if (!frame_)
756 return; 714 return;
757 if (!frame_->settings()->isJavaScriptEnabled()) 715 if (!frame_->settings()->isJavaScriptEnabled())
758 return; 716 return;
759 // TODO(mbelshe): Move this to the ScriptController and make it JS neutral. 717 // TODO(mbelshe): Move this to the ScriptController and make it JS neutral.
760 #if USE(V8) 718 #if USE(V8)
761 frame_->script()->collectGarbage(); 719 frame_->script()->collectGarbage();
762 #endif 720 #endif
763 } 721 }
764 722
765 void WebFrameImpl::GrantUniversalAccess() { 723 void WebFrameImpl::grantUniversalAccess() {
766 DCHECK(frame_ && frame_->document()); 724 DCHECK(frame_ && frame_->document());
767 if (frame_ && frame_->document()) { 725 if (frame_ && frame_->document()) {
768 frame_->document()->securityOrigin()->grantUniversalAccess(); 726 frame_->document()->securityOrigin()->grantUniversalAccess();
769 } 727 }
770 } 728 }
771 729
772 void WebFrameImpl::GetContentAsPlainText(int max_chars, 730 WebString WebFrameImpl::contentAsText(size_t max_chars) const {
773 std::wstring* text) const {
774 text->clear();
775 if (!frame_) 731 if (!frame_)
776 return; 732 return WebString();
777 733
778 FrameContentAsPlainText(max_chars, frame_, text); 734 std::wstring text;
735 FrameContentAsPlainText(max_chars, frame_, &text);
736 // TODO(darin): Too many string copies!!!
737 return WideToUTF16Hack(text);
779 } 738 }
780 739
781 NPObject* WebFrameImpl::GetWindowNPObject() { 740 NPObject* WebFrameImpl::windowObject() const {
782 if (!frame_) 741 if (!frame_)
783 return NULL; 742 return NULL;
784 743
785 return frame_->script()->windowScriptNPObject(); 744 return frame_->script()->windowScriptNPObject();
786 } 745 }
787 746
788 #if USE(V8) 747 #if USE(V8)
789 // Returns the V8 context for this frame, or an empty handle if there is 748 // Returns the V8 context for this frame, or an empty handle if there is
790 // none. 749 // none.
791 v8::Local<v8::Context> WebFrameImpl::GetMainWorldScriptContext() { 750 v8::Local<v8::Context> WebFrameImpl::mainWorldScriptContext() const {
792 if (!frame_) 751 if (!frame_)
793 return v8::Local<v8::Context>(); 752 return v8::Local<v8::Context>();
794 753
795 return WebCore::V8Proxy::mainWorldContext(frame_); 754 return WebCore::V8Proxy::mainWorldContext(frame_);
796 } 755 }
797 #endif 756 #endif
798 757
799 void WebFrameImpl::InvalidateArea(AreaToInvalidate area) { 758 void WebFrameImpl::InvalidateArea(AreaToInvalidate area) {
800 ASSERT(frame() && frame()->view()); 759 ASSERT(frame() && frame()->view());
801 FrameView* view = frame()->view(); 760 FrameView* view = frame()->view();
(...skipping 11 matching lines...) Expand all
813 // Invalidate the vertical scroll bar region for the view. 772 // Invalidate the vertical scroll bar region for the view.
814 IntRect scroll_bar_vert( 773 IntRect scroll_bar_vert(
815 view->x() + view->visibleWidth(), view->y(), 774 view->x() + view->visibleWidth(), view->y(),
816 WebCore::ScrollbarTheme::nativeTheme()->scrollbarThickness(), 775 WebCore::ScrollbarTheme::nativeTheme()->scrollbarThickness(),
817 view->visibleHeight()); 776 view->visibleHeight());
818 view->invalidateRect(scroll_bar_vert); 777 view->invalidateRect(scroll_bar_vert);
819 } 778 }
820 } 779 }
821 } 780 }
822 781
823 void WebFrameImpl::IncreaseMatchCount(int count, int request_id) { 782 void WebFrameImpl::increaseMatchCount(int count, int request_id) {
824 // This function should only be called on the mainframe. 783 // This function should only be called on the mainframe.
825 DCHECK(this == static_cast<WebFrameImpl*>(GetView()->GetMainFrame())); 784 DCHECK(!parent());
826 785
827 total_matchcount_ += count; 786 total_matchcount_ += count;
828 787
829 // Update the UI with the latest findings. 788 // Update the UI with the latest findings.
830 WebViewDelegate* webview_delegate = GetView()->GetDelegate(); 789 WebViewDelegate* webview_delegate = GetWebViewImpl()->GetDelegate();
831 DCHECK(webview_delegate); 790 DCHECK(webview_delegate);
832 if (webview_delegate) 791 if (webview_delegate)
833 webview_delegate->ReportFindInPageMatchCount(total_matchcount_, request_id, 792 webview_delegate->ReportFindInPageMatchCount(total_matchcount_, request_id,
834 frames_scoping_count_ == 0); 793 frames_scoping_count_ == 0);
835 } 794 }
836 795
837 void WebFrameImpl::ReportFindInPageSelection(const WebRect& selection_rect, 796 void WebFrameImpl::reportFindInPageSelection(const WebRect& selection_rect,
838 int active_match_ordinal, 797 int active_match_ordinal,
839 int request_id) { 798 int request_id) {
840 // Update the UI with the latest selection rect. 799 // Update the UI with the latest selection rect.
841 WebViewDelegate* webview_delegate = GetView()->GetDelegate(); 800 WebViewDelegate* webview_delegate = GetWebViewImpl()->GetDelegate();
842 DCHECK(webview_delegate); 801 DCHECK(webview_delegate);
843 if (webview_delegate) { 802 if (webview_delegate) {
844 webview_delegate->ReportFindInPageSelection( 803 webview_delegate->ReportFindInPageSelection(
845 request_id, 804 request_id,
846 OrdinalOfFirstMatchForFrame(this) + active_match_ordinal, 805 OrdinalOfFirstMatchForFrame(this) + active_match_ordinal,
847 selection_rect); 806 selection_rect);
848 } 807 }
849 } 808 }
850 809
851 void WebFrameImpl::ResetMatchCount() { 810 void WebFrameImpl::resetMatchCount() {
852 total_matchcount_ = 0; 811 total_matchcount_ = 0;
853 frames_scoping_count_ = 0; 812 frames_scoping_count_ = 0;
854 } 813 }
855 814
856 bool WebFrameImpl::Find(int request_id, 815 bool WebFrameImpl::find(int request_id,
857 const string16& search_text, 816 const WebString& search_text,
858 const WebFindOptions& options, 817 const WebFindOptions& options,
859 bool wrap_within_frame, 818 bool wrap_within_frame,
860 WebRect* selection_rect) { 819 WebRect* selection_rect) {
861 WebCore::String webcore_string = webkit_glue::String16ToString(search_text); 820 WebCore::String webcore_string = webkit_glue::WebStringToString(search_text);
862 821
863 WebFrameImpl* const main_frame_impl = 822 WebFrameImpl* const main_frame_impl = GetWebViewImpl()->main_frame();
864 static_cast<WebFrameImpl*>(GetView()->GetMainFrame());
865 823
866 if (!options.findNext) 824 if (!options.findNext)
867 frame()->page()->unmarkAllTextMatches(); 825 frame()->page()->unmarkAllTextMatches();
868 else 826 else
869 SetMarkerActive(active_match_.get(), false); // Active match is changing. 827 SetMarkerActive(active_match_.get(), false); // Active match is changing.
870 828
871 // Starts the search from the current selection. 829 // Starts the search from the current selection.
872 bool start_in_selection = true; 830 bool start_in_selection = true;
873 831
874 // If the user has selected something since the last Find operation we want 832 // If the user has selected something since the last Find operation we want
(...skipping 25 matching lines...) Expand all
900 // be active but we still continue searching. This matches Safari's 858 // be active but we still continue searching. This matches Safari's
901 // behavior, including some oddities when selectable and un-selectable text 859 // behavior, including some oddities when selectable and un-selectable text
902 // are mixed on a page: see https://bugs.webkit.org/show_bug.cgi?id=19127. 860 // are mixed on a page: see https://bugs.webkit.org/show_bug.cgi?id=19127.
903 if (new_selection.isNone() || 861 if (new_selection.isNone() ||
904 (new_selection.start() == new_selection.end())) { 862 (new_selection.start() == new_selection.end())) {
905 active_match_ = NULL; 863 active_match_ = NULL;
906 } else { 864 } else {
907 active_match_ = new_selection.toNormalizedRange(); 865 active_match_ = new_selection.toNormalizedRange();
908 curr_selection_rect = active_match_->boundingBox(); 866 curr_selection_rect = active_match_->boundingBox();
909 SetMarkerActive(active_match_.get(), true); // Active. 867 SetMarkerActive(active_match_.get(), true); // Active.
910 ClearSelection(); // WebKit draws the highlighting for all matches. 868 clearSelection(); // WebKit draws the highlighting for all matches.
911 } 869 }
912 870
913 if (!options.findNext) { 871 if (!options.findNext) {
914 // This is a Find operation, so we set the flag to ask the scoping effort 872 // This is a Find operation, so we set the flag to ask the scoping effort
915 // to find the active rect for us so we can update the ordinal (n of m). 873 // to find the active rect for us so we can update the ordinal (n of m).
916 locating_active_rect_ = true; 874 locating_active_rect_ = true;
917 } else { 875 } else {
918 if (old_active_frame != this) { 876 if (old_active_frame != this) {
919 // If the active frame has changed it means that we have a multi-frame 877 // If the active frame has changed it means that we have a multi-frame
920 // page and we just switch to searching in a new frame. Then we just 878 // page and we just switch to searching in a new frame. Then we just
(...skipping 11 matching lines...) Expand all
932 if (active_match_index_ + 1 == 0) 890 if (active_match_index_ + 1 == 0)
933 active_match_index_ = last_match_count_ - 1; 891 active_match_index_ = last_match_count_ - 1;
934 } 892 }
935 if (selection_rect) { 893 if (selection_rect) {
936 WebRect rect = webkit_glue::IntRectToWebRect( 894 WebRect rect = webkit_glue::IntRectToWebRect(
937 frame()->view()->convertToContainingWindow(curr_selection_rect)); 895 frame()->view()->convertToContainingWindow(curr_selection_rect));
938 rect.x -= frameview()->scrollOffset().width(); 896 rect.x -= frameview()->scrollOffset().width();
939 rect.y -= frameview()->scrollOffset().height(); 897 rect.y -= frameview()->scrollOffset().height();
940 *selection_rect = rect; 898 *selection_rect = rect;
941 899
942 ReportFindInPageSelection(rect, 900 reportFindInPageSelection(rect,
943 active_match_index_ + 1, 901 active_match_index_ + 1,
944 request_id); 902 request_id);
945 } 903 }
946 } 904 }
947 } else { 905 } else {
948 // Nothing was found in this frame. 906 // Nothing was found in this frame.
949 active_match_ = NULL; 907 active_match_ = NULL;
950 908
951 // Erase all previous tickmarks and highlighting. 909 // Erase all previous tickmarks and highlighting.
952 InvalidateArea(INVALIDATE_ALL); 910 InvalidateArea(INVALIDATE_ALL);
953 } 911 }
954 912
955 return found; 913 return found;
956 } 914 }
957 915
958 int WebFrameImpl::OrdinalOfFirstMatchForFrame(WebFrameImpl* frame) const { 916 int WebFrameImpl::OrdinalOfFirstMatchForFrame(WebFrameImpl* frame) const {
959 int ordinal = 0; 917 int ordinal = 0;
960 WebViewImpl* web_view = GetWebViewImpl(); 918 WebViewImpl* web_view = GetWebViewImpl();
961 WebFrameImpl* const main_frame_impl = 919 WebFrameImpl* const main_frame_impl = GetWebViewImpl()->main_frame();
962 static_cast<WebFrameImpl*>(GetView()->GetMainFrame());
963 // Iterate from the main frame up to (but not including) |frame| and 920 // Iterate from the main frame up to (but not including) |frame| and
964 // add up the number of matches found so far. 921 // add up the number of matches found so far.
965 for (WebFrameImpl* it = main_frame_impl; 922 for (WebFrameImpl* it = main_frame_impl;
966 it != frame; 923 it != frame;
967 it = static_cast<WebFrameImpl*>( 924 it = static_cast<WebFrameImpl*>(
968 web_view->GetNextFrameAfter(it, true))) { 925 web_view->GetNextFrameAfter(it, true))) {
969 if (it->last_match_count_ > 0) 926 if (it->last_match_count_ > 0)
970 ordinal += it->last_match_count_; 927 ordinal += it->last_match_count_;
971 } 928 }
972 929
973 return ordinal; 930 return ordinal;
974 } 931 }
975 932
976 bool WebFrameImpl::ShouldScopeMatches(const string16& search_text) { 933 bool WebFrameImpl::ShouldScopeMatches(const string16& search_text) {
977 // Don't scope if we can't find a frame or if the frame is not visible. 934 // Don't scope if we can't find a frame or if the frame is not visible.
978 // The user may have closed the tab/application, so abort. 935 // The user may have closed the tab/application, so abort.
979 if (!frame() || !Visible()) 936 if (!frame() || !hasVisibleContent())
980 return false; 937 return false;
981 938
982 DCHECK(frame()->document() && frame()->view()); 939 DCHECK(frame()->document() && frame()->view());
983 940
984 // If the frame completed the scoping operation and found 0 matches the last 941 // If the frame completed the scoping operation and found 0 matches the last
985 // time it was searched, then we don't have to search it again if the user is 942 // time it was searched, then we don't have to search it again if the user is
986 // just adding to the search string or sending the same search string again. 943 // just adding to the search string or sending the same search string again.
987 if (scoping_complete_ && 944 if (scoping_complete_ &&
988 !last_search_string_.empty() && last_match_count_ == 0) { 945 !last_search_string_.empty() && last_match_count_ == 0) {
989 // Check to see if the search string prefixes match. 946 // Check to see if the search string prefixes match.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 } 1007 }
1051 } 1008 }
1052 1009
1053 void WebFrameImpl::SetMarkerActive(WebCore::Range* range, bool active) { 1010 void WebFrameImpl::SetMarkerActive(WebCore::Range* range, bool active) {
1054 if (!range) 1011 if (!range)
1055 return; 1012 return;
1056 1013
1057 frame()->document()->setMarkersActive(range, active); 1014 frame()->document()->setMarkersActive(range, active);
1058 } 1015 }
1059 1016
1060 void WebFrameImpl::ScopeStringMatches(int request_id, 1017 void WebFrameImpl::scopeStringMatches(int request_id,
1061 const string16& search_text, 1018 const WebString& search_text,
1062 const WebFindOptions& options, 1019 const WebFindOptions& options,
1063 bool reset) { 1020 bool reset) {
1064 if (!ShouldScopeMatches(search_text)) 1021 if (!ShouldScopeMatches(search_text))
1065 return; 1022 return;
1066 1023
1067 WebFrameImpl* main_frame_impl = 1024 WebFrameImpl* main_frame_impl = GetWebViewImpl()->main_frame();
1068 static_cast<WebFrameImpl*>(GetView()->GetMainFrame());
1069 1025
1070 if (reset) { 1026 if (reset) {
1071 // This is a brand new search, so we need to reset everything. 1027 // This is a brand new search, so we need to reset everything.
1072 // Scoping is just about to begin. 1028 // Scoping is just about to begin.
1073 scoping_complete_ = false; 1029 scoping_complete_ = false;
1074 // Clear highlighting for this frame. 1030 // Clear highlighting for this frame.
1075 if (frame()->markedTextMatchesAreHighlighted()) 1031 if (frame()->markedTextMatchesAreHighlighted())
1076 frame()->page()->unmarkAllTextMatches(); 1032 frame()->page()->unmarkAllTextMatches();
1077 // Clear the counters from last operation. 1033 // Clear the counters from last operation.
1078 last_match_count_ = 0; 1034 last_match_count_ = 0;
1079 next_invalidate_after_ = 0; 1035 next_invalidate_after_ = 0;
1080 1036
1081 resume_scoping_from_range_ = NULL; 1037 resume_scoping_from_range_ = NULL;
1082 1038
1083 main_frame_impl->frames_scoping_count_++; 1039 main_frame_impl->frames_scoping_count_++;
1084 1040
1085 // Now, defer scoping until later to allow find operation to finish quickly. 1041 // Now, defer scoping until later to allow find operation to finish quickly.
1086 MessageLoop::current()->PostTask(FROM_HERE, 1042 MessageLoop::current()->PostTask(FROM_HERE,
1087 scope_matches_factory_.NewRunnableMethod( 1043 scope_matches_factory_.NewRunnableMethod(
1088 &WebFrameImpl::ScopeStringMatches, 1044 &WebFrameImpl::scopeStringMatches,
1089 request_id, 1045 request_id,
1090 search_text, 1046 search_text,
1091 options, 1047 options,
1092 false)); // false=we just reset, so don't do it again. 1048 false)); // false=we just reset, so don't do it again.
1093 return; 1049 return;
1094 } 1050 }
1095 1051
1096 WebCore::String webcore_string = webkit_glue::String16ToString(search_text); 1052 WebCore::String webcore_string = webkit_glue::String16ToString(search_text);
1097 1053
1098 RefPtr<Range> search_range(rangeOfContents(frame()->document())); 1054 RefPtr<Range> search_range(rangeOfContents(frame()->document()));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 main_frame_impl->active_match_frame_ = this; 1135 main_frame_impl->active_match_frame_ = this;
1180 found_active_match = true; 1136 found_active_match = true;
1181 // We also know which tickmark is active now. 1137 // We also know which tickmark is active now.
1182 active_match_index_ = match_count - 1; 1138 active_match_index_ = match_count - 1;
1183 // To stop looking for the active tickmark, we set this flag. 1139 // To stop looking for the active tickmark, we set this flag.
1184 locating_active_rect_ = false; 1140 locating_active_rect_ = false;
1185 1141
1186 // Notify browser of new location for the selected rectangle. 1142 // Notify browser of new location for the selected rectangle.
1187 result_bounds.move(-frameview()->scrollOffset().width(), 1143 result_bounds.move(-frameview()->scrollOffset().width(),
1188 -frameview()->scrollOffset().height()); 1144 -frameview()->scrollOffset().height());
1189 ReportFindInPageSelection( 1145 reportFindInPageSelection(
1190 webkit_glue::IntRectToWebRect( 1146 webkit_glue::IntRectToWebRect(
1191 frame()->view()->convertToContainingWindow(result_bounds)), 1147 frame()->view()->convertToContainingWindow(result_bounds)),
1192 active_match_index_ + 1, 1148 active_match_index_ + 1,
1193 request_id); 1149 request_id);
1194 } 1150 }
1195 1151
1196 AddMarker(result_range.get(), found_active_match); 1152 AddMarker(result_range.get(), found_active_match);
1197 } 1153 }
1198 1154
1199 resume_scoping_from_range_ = result_range; 1155 resume_scoping_from_range_ = result_range;
1200 timeout = (Time::Now() - start_time).InMilliseconds() >= kTimeout; 1156 timeout = (Time::Now() - start_time).InMilliseconds() >= kTimeout;
1201 } while (!timeout); 1157 } while (!timeout);
1202 1158
1203 // Remember what we search for last time, so we can skip searching if more 1159 // Remember what we search for last time, so we can skip searching if more
1204 // letters are added to the search string (and last outcome was 0). 1160 // letters are added to the search string (and last outcome was 0).
1205 last_search_string_ = search_text; 1161 last_search_string_ = search_text;
1206 1162
1207 if (match_count > 0) { 1163 if (match_count > 0) {
1208 frame()->setMarkedTextMatchesAreHighlighted(true); 1164 frame()->setMarkedTextMatchesAreHighlighted(true);
1209 1165
1210 last_match_count_ += match_count; 1166 last_match_count_ += match_count;
1211 1167
1212 // Let the mainframe know how much we found during this pass. 1168 // Let the mainframe know how much we found during this pass.
1213 main_frame_impl->IncreaseMatchCount(match_count, request_id); 1169 main_frame_impl->increaseMatchCount(match_count, request_id);
1214 } 1170 }
1215 1171
1216 if (timeout) { 1172 if (timeout) {
1217 // If we found anything during this pass, we should redraw. However, we 1173 // If we found anything during this pass, we should redraw. However, we
1218 // don't want to spam too much if the page is extremely long, so if we 1174 // don't want to spam too much if the page is extremely long, so if we
1219 // reach a certain point we start throttling the redraw requests. 1175 // reach a certain point we start throttling the redraw requests.
1220 if (match_count > 0) 1176 if (match_count > 0)
1221 InvalidateIfNecessary(); 1177 InvalidateIfNecessary();
1222 1178
1223 // Scoping effort ran out of time, lets ask for another time-slice. 1179 // Scoping effort ran out of time, lets ask for another time-slice.
1224 MessageLoop::current()->PostTask(FROM_HERE, 1180 MessageLoop::current()->PostTask(FROM_HERE,
1225 scope_matches_factory_.NewRunnableMethod( 1181 scope_matches_factory_.NewRunnableMethod(
1226 &WebFrameImpl::ScopeStringMatches, 1182 &WebFrameImpl::scopeStringMatches,
1227 request_id, 1183 request_id,
1228 search_text, 1184 search_text,
1229 options, 1185 options,
1230 false)); // don't reset. 1186 false)); // don't reset.
1231 1187
1232 return; // Done for now, resume work later. 1188 return; // Done for now, resume work later.
1233 } 1189 }
1234 1190
1235 // This frame has no further scoping left, so it is done. Other frames might, 1191 // This frame has no further scoping left, so it is done. Other frames might,
1236 // of course, continue to scope matches. 1192 // of course, continue to scope matches.
1237 scoping_complete_ = true; 1193 scoping_complete_ = true;
1238 main_frame_impl->frames_scoping_count_--; 1194 main_frame_impl->frames_scoping_count_--;
1239 1195
1240 // If this is the last frame to finish scoping we need to trigger the final 1196 // If this is the last frame to finish scoping we need to trigger the final
1241 // update to be sent. 1197 // update to be sent.
1242 if (main_frame_impl->frames_scoping_count_ == 0) 1198 if (main_frame_impl->frames_scoping_count_ == 0)
1243 main_frame_impl->IncreaseMatchCount(0, request_id); 1199 main_frame_impl->increaseMatchCount(0, request_id);
1244 1200
1245 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet. 1201 // This frame is done, so show any scrollbar tickmarks we haven't drawn yet.
1246 InvalidateArea(INVALIDATE_SCROLLBAR); 1202 InvalidateArea(INVALIDATE_SCROLLBAR);
1247 } 1203 }
1248 1204
1249 void WebFrameImpl::CancelPendingScopingEffort() { 1205 void WebFrameImpl::cancelPendingScopingEffort() {
1250 scope_matches_factory_.RevokeAll(); 1206 scope_matches_factory_.RevokeAll();
1251 active_match_index_ = -1; 1207 active_match_index_ = -1;
1252 } 1208 }
1253 1209
1254 void WebFrameImpl::SetFindEndstateFocusAndSelection() { 1210 void WebFrameImpl::SetFindEndstateFocusAndSelection() {
1255 WebFrameImpl* main_frame_impl = 1211 WebFrameImpl* main_frame_impl = GetWebViewImpl()->main_frame();
1256 static_cast<WebFrameImpl*>(GetView()->GetMainFrame());
1257 1212
1258 if (this == main_frame_impl->active_match_frame() && 1213 if (this == main_frame_impl->active_match_frame() &&
1259 active_match_.get()) { 1214 active_match_.get()) {
1260 // If the user has set the selection since the match was found, we 1215 // If the user has set the selection since the match was found, we
1261 // don't focus anything. 1216 // don't focus anything.
1262 VisibleSelection selection(frame()->selection()->selection()); 1217 VisibleSelection selection(frame()->selection()->selection());
1263 if (!selection.isNone()) 1218 if (!selection.isNone())
1264 return; 1219 return;
1265 1220
1266 // Try to find the first focusable node up the chain, which will, for 1221 // Try to find the first focusable node up the chain, which will, for
(...skipping 14 matching lines...) Expand all
1281 if (node->isFocusable()) { 1236 if (node->isFocusable()) {
1282 frame()->document()->setFocusedNode(node); 1237 frame()->document()->setFocusedNode(node);
1283 break; 1238 break;
1284 } 1239 }
1285 node = node->traverseNextNode(); 1240 node = node->traverseNextNode();
1286 } 1241 }
1287 } 1242 }
1288 } 1243 }
1289 } 1244 }
1290 1245
1291 void WebFrameImpl::StopFinding(bool clear_selection) { 1246 void WebFrameImpl::stopFinding(bool clear_selection) {
1292 if (!clear_selection) 1247 if (!clear_selection)
1293 SetFindEndstateFocusAndSelection(); 1248 SetFindEndstateFocusAndSelection();
1294 CancelPendingScopingEffort(); 1249 cancelPendingScopingEffort();
1295 1250
1296 // Remove all markers for matches found and turn off the highlighting. 1251 // Remove all markers for matches found and turn off the highlighting.
1297 if (this == static_cast<WebFrameImpl*>(GetView()->GetMainFrame())) 1252 if (!parent())
1298 frame()->document()->removeMarkers(WebCore::DocumentMarker::TextMatch); 1253 frame()->document()->removeMarkers(WebCore::DocumentMarker::TextMatch);
1299 frame()->setMarkedTextMatchesAreHighlighted(false); 1254 frame()->setMarkedTextMatchesAreHighlighted(false);
1300 1255
1301 // Let the frame know that we don't want tickmarks or highlighting anymore. 1256 // Let the frame know that we don't want tickmarks or highlighting anymore.
1302 InvalidateArea(INVALIDATE_ALL); 1257 InvalidateArea(INVALIDATE_ALL);
1303 } 1258 }
1304 1259
1305 void WebFrameImpl::SelectAll() { 1260 void WebFrameImpl::selectAll() {
1306 frame()->selection()->selectAll(); 1261 frame()->selection()->selectAll();
1307 1262
1308 WebViewDelegate* d = GetView()->GetDelegate(); 1263 WebViewDelegate* d = GetWebViewImpl()->GetDelegate();
1309 if (d) 1264 if (d)
1310 d->UserMetricsRecordAction(L"SelectAll"); 1265 d->UserMetricsRecordAction(L"SelectAll");
1311 } 1266 }
1312 1267
1313 void WebFrameImpl::Copy() { 1268 WebRange WebFrameImpl::selectionRange() const {
1314 frame()->editor()->copy(); 1269 return webkit_glue::RangeToWebRange(
1315 1270 frame()->selection()->toNormalizedRange());
1316 WebViewDelegate* d = GetView()->GetDelegate();
1317 if (d)
1318 d->UserMetricsRecordAction(L"Copy");
1319 } 1271 }
1320 1272
1321 void WebFrameImpl::Cut() { 1273 WebString WebFrameImpl::selectionAsText() const {
1322 frame()->editor()->cut(); 1274 RefPtr<Range> range = frame()->selection()->toNormalizedRange();
1275 if (!range.get())
1276 return WebString();
1323 1277
1324 WebViewDelegate* d = GetView()->GetDelegate(); 1278 String text = range->text();
1325 if (d) 1279 #if defined(OS_WIN)
1326 d->UserMetricsRecordAction(L"Cut"); 1280 WebCore::replaceNewlinesWithWindowsStyleNewlines(text);
1281 #endif
1282 WebCore::replaceNBSPWithSpace(text);
1283 return webkit_glue::StringToWebString(text);
1327 } 1284 }
1328 1285
1329 void WebFrameImpl::Paste() { 1286 WebString WebFrameImpl::selectionAsMarkup() const {
1330 frame()->editor()->paste(); 1287 RefPtr<Range> range = frame()->selection()->toNormalizedRange();
1288 if (!range.get())
1289 return WebString();
1331 1290
1332 WebViewDelegate* d = GetView()->GetDelegate(); 1291 String markup = WebCore::createMarkup(range.get(), 0);
1333 if (d) 1292 return webkit_glue::StringToWebString(markup);
1334 d->UserMetricsRecordAction(L"Paste");
1335 } 1293 }
1336 1294
1337 void WebFrameImpl::Replace(const std::wstring& wtext) { 1295 void WebFrameImpl::replaceSelection(const WebString& wtext) {
1338 String text = webkit_glue::StdWStringToString(wtext); 1296 String text = webkit_glue::WebStringToString(wtext);
1339 RefPtr<DocumentFragment> fragment = createFragmentFromText( 1297 RefPtr<DocumentFragment> fragment = createFragmentFromText(
1340 frame()->selection()->toNormalizedRange().get(), text); 1298 frame()->selection()->toNormalizedRange().get(), text);
1341 WebCore::applyCommand(WebCore::ReplaceSelectionCommand::create( 1299 WebCore::applyCommand(WebCore::ReplaceSelectionCommand::create(
1342 frame()->document(), fragment.get(), false, true, true)); 1300 frame()->document(), fragment.get(), false, true, true));
1343 } 1301 }
1344 1302
1345 void WebFrameImpl::ToggleSpellCheck() { 1303 void WebFrameImpl::insertText(const WebString& text) {
1304 frame()->editor()->insertText(webkit_glue::WebStringToString(text), NULL);
1305 }
1306
1307 void WebFrameImpl::setMarkedText(
1308 const WebString& text, unsigned location, unsigned length) {
1309 WebCore::Editor* editor = frame()->editor();
1310 WebCore::String str = webkit_glue::WebStringToString(text);
1311
1312 editor->confirmComposition(str);
1313
1314 WTF::Vector<WebCore::CompositionUnderline> decorations;
1315 editor->setComposition(str, decorations, location, length);
1316 }
1317
1318 void WebFrameImpl::unmarkText() {
1319 frame()->editor()->confirmCompositionWithoutDisturbingSelection();
1320 }
1321
1322 bool WebFrameImpl::hasMarkedText() const {
1323 return frame()->editor()->hasComposition();
1324 }
1325
1326 WebRange WebFrameImpl::markedRange() const {
1327 return webkit_glue::RangeToWebRange(frame()->editor()->compositionRange());
1328 }
1329
1330 void WebFrameImpl::enableContinuousSpellChecking(bool enable) {
1331 if (enable == isContinuousSpellCheckingEnabled())
1332 return;
1346 frame()->editor()->toggleContinuousSpellChecking(); 1333 frame()->editor()->toggleContinuousSpellChecking();
1347 } 1334 }
1348 1335
1349 bool WebFrameImpl::SpellCheckEnabled() { 1336 bool WebFrameImpl::isContinuousSpellCheckingEnabled() const {
1350 return frame()->editor()->isContinuousSpellCheckingEnabled(); 1337 return frame()->editor()->isContinuousSpellCheckingEnabled();
1351 } 1338 }
1352 1339
1353 void WebFrameImpl::Delete() { 1340 void WebFrameImpl::clearSelection() {
1354 frame()->editor()->command("Delete").execute();
1355
1356 WebViewDelegate* d = GetView()->GetDelegate();
1357 if (d)
1358 d->UserMetricsRecordAction(L"DeleteSelection");
1359 }
1360
1361 void WebFrameImpl::Undo() {
1362 frame()->editor()->undo();
1363
1364 WebViewDelegate* d = GetView()->GetDelegate();
1365 if (d)
1366 d->UserMetricsRecordAction(L"Undo");
1367 }
1368
1369 void WebFrameImpl::Redo() {
1370 frame()->editor()->redo();
1371
1372 WebViewDelegate* d = GetView()->GetDelegate();
1373 if (d)
1374 d->UserMetricsRecordAction(L"Redo");
1375 }
1376
1377 void WebFrameImpl::ClearSelection() {
1378 frame()->selection()->clear(); 1341 frame()->selection()->clear();
1379 } 1342 }
1380 1343
1381 bool WebFrameImpl::HasSelection() { 1344 bool WebFrameImpl::hasSelection() const {
1382 // frame()->selection()->isNone() never returns true. 1345 // frame()->selection()->isNone() never returns true.
1383 return (frame()->selection()->start() != 1346 return (frame()->selection()->start() != frame()->selection()->end());
1384 frame()->selection()->end());
1385 } 1347 }
1386 1348
1387 std::string WebFrameImpl::GetSelection(bool as_html) { 1349 WebString WebFrameImpl::contentAsMarkup() const {
1388 RefPtr<Range> range = frame()->selection()->toNormalizedRange(); 1350 return webkit_glue::StringToWebString(createFullMarkup(frame_->document()));
1389 if (!range.get())
1390 return std::string();
1391
1392 if (as_html) {
1393 String markup = WebCore::createMarkup(range.get(), 0);
1394 return webkit_glue::StringToStdString(markup);
1395 } else {
1396 String text = range->text();
1397 #if defined(OS_WIN)
1398 WebCore::replaceNewlinesWithWindowsStyleNewlines(text);
1399 #endif
1400 WebCore::replaceNBSPWithSpace(text);
1401 return webkit_glue::StringToStdString(text);
1402 }
1403 }
1404
1405 std::string WebFrameImpl::GetFullPageHtml() {
1406 return webkit_glue::StringToStdString(createFullMarkup(frame_->document()));
1407 } 1351 }
1408 1352
1409 void WebFrameImpl::CreateFrameView() { 1353 void WebFrameImpl::CreateFrameView() {
1410 ASSERT(frame_); // If frame_ doesn't exist, we probably didn't init properly. 1354 ASSERT(frame_); // If frame_ doesn't exist, we probably didn't init properly.
1411 1355
1412 WebCore::Page* page = frame_->page(); 1356 WebCore::Page* page = frame_->page();
1413 DCHECK(page); 1357 DCHECK(page);
1414 1358
1415 DCHECK(page->mainFrame() != NULL); 1359 DCHECK(page->mainFrame() != NULL);
1416 1360
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 const WebURLError& web_error = 1462 const WebURLError& web_error =
1519 webkit_glue::ResourceErrorToWebURLError(error); 1463 webkit_glue::ResourceErrorToWebURLError(error);
1520 if (was_provisional) { 1464 if (was_provisional) {
1521 delegate->DidFailProvisionalLoadWithError(web_view, web_error, this); 1465 delegate->DidFailProvisionalLoadWithError(web_view, web_error, this);
1522 } else { 1466 } else {
1523 delegate->DidFailLoadWithError(web_view, web_error, this); 1467 delegate->DidFailLoadWithError(web_view, web_error, this);
1524 } 1468 }
1525 } 1469 }
1526 } 1470 }
1527 1471
1528 void WebFrameImpl::DispatchWillSendRequest(WebURLRequest* request) { 1472 void WebFrameImpl::dispatchWillSendRequest(WebURLRequest& request) {
1529 ResourceResponse response; 1473 ResourceResponse response;
1530 frame_->loader()->client()->dispatchWillSendRequest(NULL, 0, 1474 frame_->loader()->client()->dispatchWillSendRequest(NULL, 0,
1531 *webkit_glue::WebURLRequestToMutableResourceRequest(request), 1475 *webkit_glue::WebURLRequestToMutableResourceRequest(&request),
1532 response); 1476 response);
1533 } 1477 }
1534 1478
1535 void WebFrameImpl::CommitDocumentData(const char* data, size_t data_len) { 1479 void WebFrameImpl::commitDocumentData(const char* data, size_t data_len) {
1536 DocumentLoader* document_loader = frame_->loader()->documentLoader(); 1480 DocumentLoader* document_loader = frame_->loader()->documentLoader();
1537 1481
1538 // Set the text encoding. This calls begin() for us. It is safe to call 1482 // Set the text encoding. This calls begin() for us. It is safe to call
1539 // this multiple times (Mac does: page/mac/WebCoreFrameBridge.mm). 1483 // this multiple times (Mac does: page/mac/WebCoreFrameBridge.mm).
1540 bool user_chosen = true; 1484 bool user_chosen = true;
1541 String encoding = document_loader->overrideEncoding(); 1485 String encoding = document_loader->overrideEncoding();
1542 if (encoding.isNull()) { 1486 if (encoding.isNull()) {
1543 user_chosen = false; 1487 user_chosen = false;
1544 encoding = document_loader->response().textEncodingName(); 1488 encoding = document_loader->response().textEncodingName();
1545 } 1489 }
1546 frame_->loader()->setEncoding(encoding, user_chosen); 1490 frame_->loader()->setEncoding(encoding, user_chosen);
1547 1491
1548 // NOTE: mac only does this if there is a document 1492 // NOTE: mac only does this if there is a document
1549 frame_->loader()->addData(data, data_len); 1493 frame_->loader()->addData(data, data_len);
1550 } 1494 }
1551 1495
1552 void WebFrameImpl::ExecuteScript(const WebScriptSource& source) { 1496 void WebFrameImpl::executeScript(const WebScriptSource& source) {
1553 frame_->loader()->executeScript( 1497 frame_->loader()->executeScript(
1554 WebCore::ScriptSourceCode( 1498 WebCore::ScriptSourceCode(
1555 webkit_glue::WebStringToString(source.code), 1499 webkit_glue::WebStringToString(source.code),
1556 webkit_glue::WebURLToKURL(source.url), 1500 webkit_glue::WebURLToKURL(source.url),
1557 source.startLine)); 1501 source.startLine));
1558 } 1502 }
1559 1503
1560 bool WebFrameImpl::InsertCSSStyles(const std::string& css) { 1504 bool WebFrameImpl::insertStyleText(const WebString& css) {
1561 Document* document = frame()->document(); 1505 Document* document = frame()->document();
1562 if (!document) 1506 if (!document)
1563 return false; 1507 return false;
1564 WebCore::Element* document_element = document->documentElement(); 1508 WebCore::Element* document_element = document->documentElement();
1565 if (!document_element) 1509 if (!document_element)
1566 return false; 1510 return false;
1567 1511
1568 RefPtr<WebCore::Element> stylesheet = document->createElement( 1512 RefPtr<WebCore::Element> stylesheet = document->createElement(
1569 WebCore::HTMLNames::styleTag, false); 1513 WebCore::HTMLNames::styleTag, false);
1570 ExceptionCode err = 0; 1514 ExceptionCode err = 0;
1571 stylesheet->setTextContent(webkit_glue::StdStringToString(css), err); 1515 stylesheet->setTextContent(webkit_glue::WebStringToString(css), err);
1572 DCHECK(!err) << "Failed to set style element content"; 1516 DCHECK(!err) << "Failed to set style element content";
1573 WebCore::Node* first = document_element->firstChild(); 1517 WebCore::Node* first = document_element->firstChild();
1574 bool success = document_element->insertBefore(stylesheet, first, err); 1518 bool success = document_element->insertBefore(stylesheet, first, err);
1575 DCHECK(success) << "Failed to insert stylesheet"; 1519 DCHECK(success) << "Failed to insert stylesheet";
1576 return success; 1520 return success;
1577 } 1521 }
1578 1522
1579 void WebFrameImpl::ExecuteScriptInNewContext( 1523 void WebFrameImpl::executeScriptInNewContext(
1580 const WebScriptSource* sources_in, int num_sources, 1524 const WebScriptSource* sources_in, unsigned num_sources,
1581 int extension_group) { 1525 int extension_group) {
1582 Vector<WebCore::ScriptSourceCode> sources; 1526 Vector<WebCore::ScriptSourceCode> sources;
1583 1527
1584 for (int i = 0; i < num_sources; ++i) { 1528 for (unsigned i = 0; i < num_sources; ++i) {
1585 sources.append(WebCore::ScriptSourceCode( 1529 sources.append(WebCore::ScriptSourceCode(
1586 webkit_glue::WebStringToString(sources_in[i].code), 1530 webkit_glue::WebStringToString(sources_in[i].code),
1587 webkit_glue::WebURLToKURL(sources_in[i].url), 1531 webkit_glue::WebURLToKURL(sources_in[i].url),
1588 sources_in[i].startLine)); 1532 sources_in[i].startLine));
1589 } 1533 }
1590 1534
1591 frame_->script()->evaluateInNewContext(sources, extension_group); 1535 frame_->script()->evaluateInNewContext(sources, extension_group);
1592 } 1536 }
1593 1537
1594 void WebFrameImpl::ExecuteScriptInNewWorld( 1538 void WebFrameImpl::executeScriptInNewWorld(
1595 const WebScriptSource* sources_in, int num_sources, 1539 const WebScriptSource* sources_in, unsigned num_sources,
1596 int extension_group) { 1540 int extension_group) {
1597 Vector<WebCore::ScriptSourceCode> sources; 1541 Vector<WebCore::ScriptSourceCode> sources;
1598 1542
1599 for (int i = 0; i < num_sources; ++i) { 1543 for (unsigned i = 0; i < num_sources; ++i) {
1600 sources.append(WebCore::ScriptSourceCode( 1544 sources.append(WebCore::ScriptSourceCode(
1601 webkit_glue::WebStringToString(sources_in[i].code), 1545 webkit_glue::WebStringToString(sources_in[i].code),
1602 webkit_glue::WebURLToKURL(sources_in[i].url), 1546 webkit_glue::WebURLToKURL(sources_in[i].url),
1603 sources_in[i].startLine)); 1547 sources_in[i].startLine));
1604 } 1548 }
1605 1549
1606 frame_->script()->evaluateInNewWorld(sources, extension_group); 1550 frame_->script()->evaluateInNewWorld(sources, extension_group);
1607 } 1551 }
1608 1552
1609 std::wstring WebFrameImpl::GetName() { 1553 WebString WebFrameImpl::name() const {
1610 return webkit_glue::StringToStdWString(frame_->tree()->name()); 1554 return webkit_glue::StringToWebString(frame_->tree()->name());
1611 } 1555 }
1612 1556
1613 WebTextInput* WebFrameImpl::GetTextInput() { 1557 bool WebFrameImpl::hasVisibleContent() const {
1614 if (!webtextinput_impl_.get()) {
1615 webtextinput_impl_.reset(new WebTextInputImpl(this));
1616 }
1617 return webtextinput_impl_.get();
1618 }
1619
1620 bool WebFrameImpl::Visible() {
1621 return frame()->view()->visibleWidth() > 0 && 1558 return frame()->view()->visibleWidth() > 0 &&
1622 frame()->view()->visibleHeight() > 0; 1559 frame()->view()->visibleHeight() > 0;
1623 } 1560 }
1624 1561
1625 PassRefPtr<Frame> WebFrameImpl::CreateChildFrame( 1562 PassRefPtr<Frame> WebFrameImpl::CreateChildFrame(
1626 const FrameLoadRequest& request, HTMLFrameOwnerElement* owner_element) { 1563 const FrameLoadRequest& request, HTMLFrameOwnerElement* owner_element) {
1627 // TODO(darin): share code with initWithName() 1564 // TODO(darin): share code with initWithName()
1628 1565
1629 scoped_refptr<WebFrameImpl> webframe = new WebFrameImpl(); 1566 scoped_refptr<WebFrameImpl> webframe = new WebFrameImpl();
1630 1567
(...skipping 30 matching lines...) Expand all
1661 1598
1662 // A synchronous navigation (about:blank) would have already processed 1599 // A synchronous navigation (about:blank) would have already processed
1663 // onload, so it is possible for the frame to have already been destroyed by 1600 // onload, so it is possible for the frame to have already been destroyed by
1664 // script in the page. 1601 // script in the page.
1665 if (!child_frame->tree()->parent()) 1602 if (!child_frame->tree()->parent())
1666 return NULL; 1603 return NULL;
1667 1604
1668 return child_frame.release(); 1605 return child_frame.release();
1669 } 1606 }
1670 1607
1671 bool WebFrameImpl::ExecuteEditCommandByName(const std::string& name, 1608 bool WebFrameImpl::executeCommand(const WebString& name) {
1672 const std::string& value) {
1673 ASSERT(frame()); 1609 ASSERT(frame());
1674 return frame()->editor()->command(webkit_glue::StdStringToString(name)) 1610
1675 .execute(webkit_glue::StdStringToString(value)); 1611 if (name.length() <= 2)
1612 return false;
1613
1614 // Since we don't have NSControl, we will convert the format of command
1615 // string and call the function on Editor directly.
1616 string16 command = name;
1617
1618 // Make sure the first letter is upper case.
1619 command.replace(0, 1, 1, toupper(command.at(0)));
1620
1621 // Remove the trailing ':' if existing.
1622 if (command.at(command.length() - 1) == ':')
1623 command.erase(command.length() - 1, 1);
1624
1625 bool rv = true;
1626
1627 // Specially handling commands that Editor::execCommand does not directly
1628 // support.
1629 if (EqualsASCII(command, "DeleteToEndOfParagraph")) {
1630 WebCore::Editor* editor = frame()->editor();
1631 if (!editor->deleteWithDirection(WebCore::SelectionController::FORWARD,
1632 WebCore::ParagraphBoundary,
1633 true,
1634 false)) {
1635 editor->deleteWithDirection(WebCore::SelectionController::FORWARD,
1636 WebCore::CharacterGranularity,
1637 true,
1638 false);
1639 }
1640 } else if (EqualsASCII(command, "Indent")) {
1641 frame()->editor()->indent();
1642 } else if (EqualsASCII(command, "Outdent")) {
1643 frame()->editor()->outdent();
1644 } else if (EqualsASCII(command, "DeleteBackward")) {
1645 rv = frame()->editor()->command(AtomicString("BackwardDelete")).execute();
1646 } else if (EqualsASCII(command, "DeleteForward")) {
1647 rv = frame()->editor()->command(AtomicString("ForwardDelete")).execute();
1648 } else {
1649 rv = frame()->editor()->command(AtomicString(command.c_str())).execute();
1650 }
1651 return rv;
1676 } 1652 }
1677 1653
1678 bool WebFrameImpl::IsEditCommandEnabled(const std::string& name) { 1654 bool WebFrameImpl::executeCommand(const WebString& name,
1655 const WebString& value) {
1679 ASSERT(frame()); 1656 ASSERT(frame());
1680 return frame()->editor()->command(webkit_glue::StdStringToString(name)) 1657 return frame()->editor()->command(webkit_glue::WebStringToString(name)).
1681 .isEnabled(); 1658 execute(webkit_glue::WebStringToString(value));
1682 } 1659 }
1683 1660
1684 void WebFrameImpl::AddMessageToConsole(const WebConsoleMessage& message) { 1661 bool WebFrameImpl::isCommandEnabled(const WebString& name) const {
1662 ASSERT(frame());
1663 return frame()->editor()->command(webkit_glue::WebStringToString(name)).
1664 isEnabled();
1665 }
1666
1667 void WebFrameImpl::addMessageToConsole(const WebConsoleMessage& message) {
1685 ASSERT(frame()); 1668 ASSERT(frame());
1686 1669
1687 WebCore::MessageLevel webcore_message_level; 1670 WebCore::MessageLevel webcore_message_level;
1688 switch (message.level) { 1671 switch (message.level) {
1689 case WebConsoleMessage::LevelTip: 1672 case WebConsoleMessage::LevelTip:
1690 webcore_message_level = WebCore::TipMessageLevel; 1673 webcore_message_level = WebCore::TipMessageLevel;
1691 break; 1674 break;
1692 case WebConsoleMessage::LevelLog: 1675 case WebConsoleMessage::LevelLog:
1693 webcore_message_level = WebCore::LogMessageLevel; 1676 webcore_message_level = WebCore::LogMessageLevel;
1694 break; 1677 break;
1695 case WebConsoleMessage::LevelWarning: 1678 case WebConsoleMessage::LevelWarning:
1696 webcore_message_level = WebCore::WarningMessageLevel; 1679 webcore_message_level = WebCore::WarningMessageLevel;
1697 break; 1680 break;
1698 case WebConsoleMessage::LevelError: 1681 case WebConsoleMessage::LevelError:
1699 webcore_message_level = WebCore::ErrorMessageLevel; 1682 webcore_message_level = WebCore::ErrorMessageLevel;
1700 break; 1683 break;
1701 default: 1684 default:
1702 NOTREACHED(); 1685 NOTREACHED();
1703 return; 1686 return;
1704 } 1687 }
1705 1688
1706 frame()->domWindow()->console()->addMessage( 1689 frame()->domWindow()->console()->addMessage(
1707 WebCore::OtherMessageSource, WebCore::LogMessageType, 1690 WebCore::OtherMessageSource, WebCore::LogMessageType,
1708 webcore_message_level, webkit_glue::WebStringToString(message.text), 1691 webcore_message_level, webkit_glue::WebStringToString(message.text),
1709 1, String()); 1692 1, String());
1710 } 1693 }
1711 1694
1712 WebSize WebFrameImpl::ScrollOffset() const { 1695 WebSize WebFrameImpl::scrollOffset() const {
1713 WebCore::FrameView* view = frameview(); 1696 WebCore::FrameView* view = frameview();
1714 if (view) 1697 if (view)
1715 return webkit_glue::IntSizeToWebSize(view->scrollOffset()); 1698 return webkit_glue::IntSizeToWebSize(view->scrollOffset());
1716 1699
1717 return WebSize(); 1700 return WebSize();
1718 } 1701 }
1719 1702
1703 WebSize WebFrameImpl::contentsSize() const {
1704 return webkit_glue::IntSizeToWebSize(frame()->view()->contentsSize());
1705 }
1706
1707 WebFrame* WebFrameImpl::firstChild() const {
1708 return FromFrame(frame()->tree()->firstChild());
1709 }
1710
1711 WebFrame* WebFrameImpl::lastChild() const {
1712 return FromFrame(frame()->tree()->lastChild());
1713 }
1714
1715 WebFrame* WebFrameImpl::nextSibling() const {
1716 return FromFrame(frame()->tree()->nextSibling());
1717 }
1718
1719 WebFrame* WebFrameImpl::previousSibling() const {
1720 return FromFrame(frame()->tree()->previousSibling());
1721 }
1722
1723 WebFrame* WebFrameImpl::traverseNext(bool wrap) const {
1724 return FromFrame(frame()->tree()->traverseNextWithWrap(wrap));
1725 }
1726
1727 WebFrame* WebFrameImpl::traversePrevious(bool wrap) const {
1728 return FromFrame(frame()->tree()->traversePreviousWithWrap(wrap));
1729 }
1730
1731 WebFrame* WebFrameImpl::findChildByName(const WebKit::WebString& name) const {
1732 return FromFrame(frame()->tree()->child(
1733 webkit_glue::WebStringToString(name)));
1734 }
1735
1736 WebFrame* WebFrameImpl::findChildByExpression(
1737 const WebKit::WebString& xpath) const {
1738 if (xpath.isEmpty())
1739 return NULL;
1740
1741 Document* document = frame_->document();
1742
1743 ExceptionCode ec = 0;
1744 PassRefPtr<XPathResult> xpath_result =
1745 document->evaluate(webkit_glue::WebStringToString(xpath),
1746 document,
1747 NULL, /* namespace */
1748 XPathResult::ORDERED_NODE_ITERATOR_TYPE,
1749 NULL, /* XPathResult object */
1750 ec);
1751 if (!xpath_result.get())
1752 return NULL;
1753
1754 Node* node = xpath_result->iterateNext(ec);
1755
1756 if (!node || !node->isFrameOwnerElement())
1757 return NULL;
1758 HTMLFrameOwnerElement* frame_element =
1759 static_cast<HTMLFrameOwnerElement*>(node);
1760 return FromFrame(frame_element->contentFrame());
1761 }
1762
1720 void WebFrameImpl::SetAllowsScrolling(bool flag) { 1763 void WebFrameImpl::SetAllowsScrolling(bool flag) {
1721 frame_->view()->setCanHaveScrollbars(flag); 1764 frame_->view()->setCanHaveScrollbars(flag);
1722 } 1765 }
1723 1766
1724 int WebFrameImpl::PrintBegin(const WebSize& page_size) { 1767 int WebFrameImpl::printBegin(const WebSize& page_size) {
1725 DCHECK_EQ(frame()->document()->isFrameSet(), false); 1768 DCHECK_EQ(frame()->document()->isFrameSet(), false);
1726 1769
1727 print_context_.reset(new ChromePrintContext(frame())); 1770 print_context_.reset(new ChromePrintContext(frame()));
1728 WebCore::FloatRect rect(0, 0, 1771 WebCore::FloatRect rect(0, 0,
1729 static_cast<float>(page_size.width), 1772 static_cast<float>(page_size.width),
1730 static_cast<float>(page_size.height)); 1773 static_cast<float>(page_size.height));
1731 print_context_->begin(rect.width()); 1774 print_context_->begin(rect.width());
1732 float page_height; 1775 float page_height;
1733 // We ignore the overlays calculation for now since they are generated in the 1776 // We ignore the overlays calculation for now since they are generated in the
1734 // browser. page_height is actually an output parameter. 1777 // browser. page_height is actually an output parameter.
1735 print_context_->computePageRects(rect, 0, 0, 1.0, page_height); 1778 print_context_->computePageRects(rect, 0, 0, 1.0, page_height);
1736 return print_context_->pageCount(); 1779 return print_context_->pageCount();
1737 } 1780 }
1738 1781
1739 float WebFrameImpl::PrintPage(int page, WebCanvas* canvas) { 1782 float WebFrameImpl::printPage(int page, WebCanvas* canvas) {
1740 // Ensure correct state. 1783 // Ensure correct state.
1741 if (!print_context_.get() || page < 0 || !frame() || !frame()->document()) { 1784 if (!print_context_.get() || page < 0 || !frame() || !frame()->document()) {
1742 NOTREACHED(); 1785 NOTREACHED();
1743 return 0; 1786 return 0;
1744 } 1787 }
1745 1788
1746 #if defined(OS_WIN) || defined(OS_LINUX) 1789 #if defined(OS_WIN) || defined(OS_LINUX)
1747 PlatformContextSkia context(canvas); 1790 PlatformContextSkia context(canvas);
1748 GraphicsContext spool(&context); 1791 GraphicsContext spool(&context);
1749 #elif defined(OS_MACOSX) 1792 #elif defined(OS_MACOSX)
1750 CGContextRef context = canvas->beginPlatformPaint(); 1793 CGContextRef context = canvas->beginPlatformPaint();
1751 GraphicsContext spool(context); 1794 GraphicsContext spool(context);
1752 WebCore::LocalCurrentGraphicsContext localContext(&spool); 1795 WebCore::LocalCurrentGraphicsContext localContext(&spool);
1753 #endif 1796 #endif
1754 1797
1755 return print_context_->spoolPage(spool, page); 1798 return print_context_->spoolPage(spool, page);
1756 } 1799 }
1757 1800
1758 void WebFrameImpl::PrintEnd() { 1801 void WebFrameImpl::printEnd() {
1759 DCHECK(print_context_.get()); 1802 DCHECK(print_context_.get());
1760 if (print_context_.get()) 1803 if (print_context_.get())
1761 print_context_->end(); 1804 print_context_->end();
1762 print_context_.reset(NULL); 1805 print_context_.reset(NULL);
1763 } 1806 }
1764 1807
1765 int WebFrameImpl::PendingFrameUnloadEventCount() const { 1808 unsigned WebFrameImpl::unloadListenerCount() const {
1766 return frame()->domWindow()->pendingUnloadEventListeners(); 1809 return frame()->domWindow()->pendingUnloadEventListeners();
1767 } 1810 }
1768 1811
1769 void WebFrameImpl::RegisterPasswordListener( 1812 void WebFrameImpl::RegisterPasswordListener(
1770 PassRefPtr<WebCore::HTMLInputElement> input_element, 1813 PassRefPtr<WebCore::HTMLInputElement> input_element,
1771 webkit_glue::PasswordAutocompleteListener* listener) { 1814 webkit_glue::PasswordAutocompleteListener* listener) {
1772 RefPtr<WebCore::HTMLInputElement> element = input_element; 1815 RefPtr<WebCore::HTMLInputElement> element = input_element;
1773 DCHECK(password_listeners_.find(element) == password_listeners_.end()); 1816 DCHECK(password_listeners_.find(element) == password_listeners_.end());
1774 password_listeners_.set(element, listener); 1817 password_listeners_.set(element, listener);
1775 } 1818 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 1851
1809 SecurityOrigin* security_origin = frame_->document()->securityOrigin(); 1852 SecurityOrigin* security_origin = frame_->document()->securityOrigin();
1810 1853
1811 if (!frame_->loader()->isScheduledLocationChangePending()) { 1854 if (!frame_->loader()->isScheduledLocationChangePending()) {
1812 frame_->loader()->stopAllLoaders(); 1855 frame_->loader()->stopAllLoaders();
1813 frame_->loader()->begin(frame_->loader()->url(), true, security_origin); 1856 frame_->loader()->begin(frame_->loader()->url(), true, security_origin);
1814 frame_->loader()->write(script_result); 1857 frame_->loader()->write(script_result);
1815 frame_->loader()->end(); 1858 frame_->loader()->end();
1816 } 1859 }
1817 } 1860 }
OLDNEW
« no previous file with comments | « webkit/glue/webframe_impl.h ('k') | webkit/glue/webframe_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698