void WebPage::handleUnsupportedContent(QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError) { BrowserApplication::downloadManager()->handleUnsupportedContent(reply); return; } QFile file(QLatin1String(":/notfound.html")); bool isOpened = file.open(QIODevice::ReadOnly); Q_ASSERT(isOpened); QString title = tr("Error loading page: %1").arg(reply->url().toString()); QString html = QString(QLatin1String(file.readAll())) .arg(title) .arg(reply->errorString()) .arg(reply->url().toString()); QBuffer imageBuffer; imageBuffer.open(QBuffer::ReadWrite); QIcon icon = view()->style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, view()); QPixmap pixmap = icon.pixmap(QSize(32,32)); if (pixmap.save(&imageBuffer, "PNG")) { html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"), QString(QLatin1String(imageBuffer.buffer().toBase64()))); } QList<QWebFrame*> frames; frames.append(mainFrame()); while (!frames.isEmpty()) { QWebFrame *frame = frames.takeFirst(); if (frame->url() == reply->url()) { frame->setHtml(html, reply->url()); return; } QList<QWebFrame *> children = frame->childFrames(); foreach(QWebFrame *frame, children) frames.append(frame); } if (m_loadingUrl == reply->url()) { mainFrame()->setHtml(html, reply->url()); } }
void Page::setMemoryCacheClientCallsEnabled(bool enabled) { if (m_areMemoryCacheClientCallsEnabled == enabled) return; m_areMemoryCacheClientCallsEnabled = enabled; if (!enabled) return; for (RefPtr<Frame> frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) frame->loader()->tellClientAboutPastMemoryCacheLoads(); }
void PinchViewport::setScale(float scale) { if (scale == m_scale) return; m_scale = scale; if (mainFrame()) mainFrame()->loader().saveScrollState(); // Old-style pinch sets scale here but we shouldn't call into the // clamping code below. if (!m_innerViewportScrollLayer) return; // Ensure we clamp so we remain within the bounds. setLocation(visibleRect().location()); // TODO: We should probably be calling scaleDidChange type functions here. // see Page::setPageScaleFactor. }
void Page::setIsInWindow(bool isInWindow) { if (m_isInWindow == isInWindow) return; m_isInWindow = isInWindow; for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) { if (FrameView* frameView = frame->view()) frameView->setIsInWindow(isInWindow); } }
IntRect VisualViewport::scrollableAreaBoundingBox() const { // This method should return the bounding box in the parent view's coordinate // space; however, VisualViewport technically isn't a child of any Frames. // Nonetheless, the VisualViewport always occupies the entire main frame so // just return that. LocalFrame* frame = mainFrame(); if (!frame || !frame->view()) return IntRect(); return frame->view()->frameRect(); }
IntPoint VisualViewport::clampDocumentOffsetAtScale(const IntPoint& offset, float scale) { if (!mainFrame() || !mainFrame()->view()) return IntPoint(); FrameView* view = mainFrame()->view(); FloatSize scaledSize(m_size); scaledSize.scale(1 / scale); IntSize visualViewportMax = flooredIntSize(FloatSize(contentsSize()) - scaledSize); IntSize max = view->maximumScrollOffsetInt() + visualViewportMax; IntSize min = view->minimumScrollOffsetInt(); // VisualViewportMin should be (0, 0) IntSize clamped = toIntSize(offset); clamped = clamped.shrunkTo(max); clamped = clamped.expandedTo(min); return IntPoint(clamped); }
LLWebPage::LLWebPage(QObject *parent) : QWebPage(parent) , window(0) , windowOpenBehavior(LLQtWebKit::WOB_IGNORE) , mHostLanguage( "en" ) { connect(this, SIGNAL(loadProgress(int)), this, SLOT(loadProgressSlot(int))); connect(this, SIGNAL(statusBarMessage(const QString &)), this, SLOT(statusBarMessageSlot(const QString &))); connect(mainFrame(), SIGNAL(urlChanged(const QUrl&)), this, SLOT(urlChangedSlot(const QUrl&))); connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted())); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); connect(mainFrame(), SIGNAL(titleChanged(const QString&)), this, SLOT(titleChangedSlot(const QString&))); connect(mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(extendNavigatorObject())); }
bool UnifiedPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { if (type == QWebPage::NavigationTypeLinkClicked) { mainFrame()->load(request); return true; } return QWebPage::acceptNavigationRequest(frame, request, type); }
void VisualViewport::setScaleAndLocation(float scale, const FloatPoint& location) { if (!mainFrame()) return; bool valuesChanged = false; if (scale != m_scale) { m_scale = scale; valuesChanged = true; frameHost().chromeClient().pageScaleFactorChanged(); } FloatPoint clampedOffset(clampOffsetToBoundaries(location)); if (clampedOffset != m_offset) { m_offset = clampedOffset; scrollAnimator()->setCurrentPosition(m_offset); // SVG runs with accelerated compositing disabled so no ScrollingCoordinator. if (ScrollingCoordinator* coordinator = frameHost().page().scrollingCoordinator()) coordinator->scrollableAreaScrollLayerDidChange(this); if (!frameHost().settings().inertVisualViewport()) { if (Document* document = mainFrame()->document()) document->enqueueScrollEventForNode(document); } mainFrame()->loader().client()->didChangeScrollOffset(); valuesChanged = true; } if (!valuesChanged) return; InspectorInstrumentation::didUpdateLayout(mainFrame()); mainFrame()->loader().saveScrollState(); clampToBoundaries(); }
void Page::setShouldSuppressScrollbarAnimations(bool suppressAnimations) { if (suppressAnimations == m_suppressScrollbarAnimations) return; if (!suppressAnimations) { // If animations are not going to be suppressed anymore, then there is nothing to do here but // change the cached value. m_suppressScrollbarAnimations = suppressAnimations; return; } // On the other hand, if we are going to start suppressing animations, then we need to make sure we // finish any current scroll animations first. FrameView* view = mainFrame()->view(); if (!view) return; view->finishCurrentScrollAnimations(); for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) { FrameView* frameView = frame->view(); if (!frameView) continue; const HashSet<ScrollableArea*>* scrollableAreas = frameView->scrollableAreas(); if (!scrollableAreas) continue; for (HashSet<ScrollableArea*>::const_iterator it = scrollableAreas->begin(), end = scrollableAreas->end(); it != end; ++it) { ScrollableArea* scrollableArea = *it; ASSERT(scrollableArea->scrollbarsCanBeActive()); scrollableArea->finishCurrentScrollAnimations(); } } m_suppressScrollbarAnimations = suppressAnimations; }
void Page::setPageScaleFactor(float scale, const IntPoint& origin) { Document* document = mainFrame()->document(); FrameView* view = document->view(); if (scale == m_pageScaleFactor) { if (view && (view->scrollPosition() != origin || view->delegatesScrolling())) { if (!m_settings->applyPageScaleFactorInCompositor()) document->updateLayoutIgnorePendingStylesheets(); view->setScrollPosition(origin); } return; } m_pageScaleFactor = scale; if (!m_settings->applyPageScaleFactorInCompositor()) { if (document->renderer()) document->renderer()->setNeedsLayout(true); document->recalcStyle(Style::Force); // Transform change on RenderView doesn't trigger repaint on non-composited contents. mainFrame()->view()->invalidateRect(IntRect(LayoutRect::infiniteRect())); } #if USE(ACCELERATED_COMPOSITING) mainFrame()->deviceOrPageScaleFactorChanged(); #endif if (view && view->fixedElementsLayoutRelativeToFrame()) view->setViewportConstrainedObjectsNeedLayout(); if (view && view->scrollPosition() != origin) { if (!m_settings->applyPageScaleFactorInCompositor() && document->renderer() && document->renderer()->needsLayout() && view->didFirstLayout()) view->layout(); view->setScrollPosition(origin); } }
void Page::setMediaVolume(float volume) { if (volume < 0 || volume > 1) return; if (m_mediaVolume == volume) return; m_mediaVolume = volume; for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) { frame->document()->mediaVolumeDidChange(); } }
void Page::storageBlockingStateChanged() { for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) frame->document()->storageBlockingStateDidChange(); // Collect the PluginViews in to a vector to ensure that action the plug-in takes // from below storageBlockingStateChanged does not affect their lifetime. Vector<RefPtr<PluginViewBase>, 32> pluginViewBases; collectPluginViews(pluginViewBases); for (size_t i = 0; i < pluginViewBases.size(); ++i) pluginViewBases[i]->storageBlockingStateChanged(); }
void PageRunner::finished(bool ok) { // bind nativeio if (!ok) { qApp->exit(1); } if (!scriptMode) { mainFrame()->evaluateJavaScript(getRuntimeBindings()); } // connect signals connect(this, SIGNAL(contentsChanged()), this, SLOT(noteChange())); connect(this, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(noteChange())); connect(this, SIGNAL(repaintRequested(QRect)), this, SLOT(noteChange())); connect(mainFrame(), SIGNAL(pageChanged()), this, SLOT(noteChange())); connect(this, SIGNAL(geometryChangeRequested(QRect)), this, SLOT(noteChange())); QTimer::singleShot(150, this, SLOT(reallyFinished())); changed = false; time.start(); }
void WebPage::handleUnsupportedContent(QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError) { if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) qDebug() << "download it"; new OpDownloader(reply); return; } if (reply->error() == QNetworkReply::ProtocolUnknownError) { // we currently don't support protocol other than http(s):// and file:// // return; } //display notfound if (reply->url().isEmpty()) return; QFile file(QLatin1String(":/notfound.html")); bool isOpened = file.open(QIODevice::ReadOnly); Q_ASSERT(isOpened); QString title = ("HTTP 404 Not Found"); QString html = QString(QLatin1String(file.readAll())); QList<QWebFrame*> frames; frames.append(mainFrame()); while (!frames.isEmpty()) { QWebFrame *frame = frames.takeFirst(); if (frame->url() == reply->url()) { frame->setHtml(html, reply->url()); return; } QList<QWebFrame *> children = frame->childFrames(); foreach (QWebFrame *frame, children) frames.append(frame); } if (m_loadingUrl == reply->url()) { mainFrame()->setHtml(html, reply->url()); } }
ArenaSize Page::renderTreeSize() const { ArenaSize total(0, 0); for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) { if (!frame->document()) continue; if (RenderArena* arena = frame->document()->renderArena()) { total.treeSize += arena->totalRenderArenaSize(); total.allocated += arena->totalRenderArenaAllocatedBytes(); } } return total; }
void InspectorPageAgent::getCookies(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Page::Cookie> >& cookies) { ListHashSet<Cookie> rawCookiesList; for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext(mainFrame())) { if (!frame->isLocalFrame()) continue; Document* document = toLocalFrame(frame)->document(); Vector<KURL> allURLs = allResourcesURLsForFrame(toLocalFrame(frame)); for (Vector<KURL>::const_iterator it = allURLs.begin(); it != allURLs.end(); ++it) { Vector<Cookie> docCookiesList; getRawCookies(document, *it, docCookiesList); int cookiesSize = docCookiesList.size(); for (int i = 0; i < cookiesSize; i++) { if (!rawCookiesList.contains(docCookiesList[i])) rawCookiesList.add(docCookiesList[i]); } } } cookies = buildArrayForCookies(rawCookiesList); }
QWebFrame* CustomWebPage::FindFrame (const QUrl& url) { QList<QWebFrame*> frames; frames.append (mainFrame ()); while (!frames.isEmpty ()) { QWebFrame *frame = frames.takeFirst (); if (frame->url () == url) return frame; frames << frame->childFrames (); } return 0; }
void CustomWebPage::handleLoadFinished (bool ok) { QWebElement body = mainFrame ()->findFirstElement ("body"); if (body.findAll ("*").count () == 1 && body.firstChild ().tagName () == "IMG") mainFrame ()->evaluateJavaScript ("function centerImg() {" "var img = document.querySelector('img');" "img.style.left = Math.floor((document.width - img.width) / 2) + 'px';" "img.style.top = Math.floor((document.height - img.height) / 2) + 'px';" "img.style.position = 'absolute';" "}" "window.addEventListener('resize', centerImg, false);" "centerImg();"); Util::DefaultHookProxy_ptr proxy (new Util::DefaultHookProxy ()); emit hookLoadFinished (proxy, this, ok); if (proxy->IsCancelled ()) return; emit delayedFillForms (mainFrame ()); }
IntRect VisualViewport::visibleContentRect( IncludeScrollbarsInRect scrollbarInclusion) const { // TODO(ymalik): We're losing precision here and below. visibleRect should // be replaced with visibleContentRect. IntRect rect = IntRect(visibleRect()); if (scrollbarInclusion == ExcludeScrollbars) { RootFrameViewport* rootFrameViewport = mainFrame()->view()->getRootFrameViewport(); DCHECK(rootFrameViewport); rect.contract(rootFrameViewport->verticalScrollbarWidth() / m_scale, rootFrameViewport->horizontalScrollbarHeight() / m_scale); } return rect; }
bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) { const QWebPage::ErrorPageExtensionOption* info = static_cast<const QWebPage::ErrorPageExtensionOption*>(option); // Lets handle error pages for the main frame for now. if (info->frame != mainFrame()) return false; QWebPage::ErrorPageExtensionReturn* errorPage = static_cast<QWebPage::ErrorPageExtensionReturn*>(output); errorPage->content = QString("data:text/html,<body/>").toUtf8(); return true; }
void Page::setPageScaleFactor(float scale, const IntPoint& origin) { FrameView* view = mainFrame()->view(); if (scale == m_pageScaleFactor) { if (view && view->scrollPosition() != origin) view->setScrollPosition(origin); return; } m_pageScaleFactor = scale; if (view) view->setVisibleContentScaleFactor(scale); mainFrame()->deviceOrPageScaleFactorChanged(); if (view) view->setViewportConstrainedObjectsNeedLayout(); if (view && view->scrollPosition() != origin) view->setScrollPosition(origin); }
void Page::acceptLanguagesChanged() { Vector< RefPtr<LocalFrame> > frames; // Even though we don't fire an event from here, the LocalDOMWindow's will fire // an event so we keep the frames alive until we are done. for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext()) { if (frame->isLocalFrame()) frames.append(toLocalFrame(frame)); } for (unsigned i = 0; i < frames.size(); ++i) frames[i]->domWindow()->acceptLanguagesChanged(); }
WebPage::WebPage(QupZilla* mainClass) : QWebPage() , p_QupZilla(mainClass) , m_view(0) , m_speedDial(mApp->plugins()->speedDial()) , m_fileWatcher(0) , m_runningLoop(0) , m_loadProgress(-1) , m_blockAlerts(false) , m_secureStatus(false) , m_adjustingScheduled(false) { m_networkProxy = new NetworkManagerProxy(this); m_networkProxy->setPrimaryNetworkAccessManager(mApp->networkManager()); m_networkProxy->setPage(this); setNetworkAccessManager(m_networkProxy); setForwardUnsupportedContent(true); setPluginFactory(new WebPluginFactory(this)); history()->setMaximumItemCount(20); connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*))); connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(finished())); connect(this, SIGNAL(printRequested(QWebFrame*)), this, SLOT(printFrame(QWebFrame*))); connect(this, SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadRequested(QNetworkRequest))); connect(this, SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested())); connect(this, SIGNAL(databaseQuotaExceeded(QWebFrame*, QString)), this, SLOT(dbQuotaExceeded(QWebFrame*))); connect(mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJavaScriptObject())); #if QTWEBKIT_FROM_2_2 connect(this, SIGNAL(featurePermissionRequested(QWebFrame*, QWebPage::Feature)), this, SLOT(featurePermissionRequested(QWebFrame*, QWebPage::Feature))); #endif #if QTWEBKIT_FROM_2_3 connect(this, SIGNAL(applicationCacheQuotaExceeded(QWebSecurityOrigin*, quint64, quint64)), this, SLOT(appCacheQuotaExceeded(QWebSecurityOrigin*, quint64))); #elif QTWEBKIT_FROM_2_2 connect(this, SIGNAL(applicationCacheQuotaExceeded(QWebSecurityOrigin*, quint64)), this, SLOT(appCacheQuotaExceeded(QWebSecurityOrigin*, quint64))); #endif s_livingPages.append(this); }
WebPage::~WebPage() { #if defined(QT_DEBUG) if (inspector) { delete inspector; inspector = NULL; } #endif disconnect(this, SLOT(on_load_finished(bool))); QWebFrame* frame = mainFrame(); if (frame) disconnect(frame, SLOT(loadFinished(bool))); triggerAction(QWebPage::Stop); }
void Page::setPageScaleFactor(float scale, const IntPoint& origin) { FrameView* view = mainFrame()->view(); bool oldProgrammaticScroll = view->inProgrammaticScroll(); view->setInProgrammaticScroll(false); if (scale != m_pageScaleFactor) { m_pageScaleFactor = scale; if (view) view->setVisibleContentScaleFactor(scale); mainFrame()->deviceOrPageScaleFactorChanged(); if (view) view->setViewportConstrainedObjectsNeedLayout(); } if (view && view->scrollPosition() != origin) view->notifyScrollPositionChanged(origin); view->setInProgrammaticScroll(oldProgrammaticScroll); }
void WebPage::finished() { progress(100); if (m_adjustingScheduled) { m_adjustingScheduled = false; mainFrame()->setZoomFactor(mainFrame()->zoomFactor() + 1); mainFrame()->setZoomFactor(mainFrame()->zoomFactor() - 1); } // File scheme watcher if (url().scheme() == QLatin1String("file")) { QFileInfo info(url().toLocalFile()); if (info.isFile()) { if (!m_fileWatcher) { m_fileWatcher = new DelayedFileWatcher(this); connect(m_fileWatcher, SIGNAL(delayedFileChanged(QString)), this, SLOT(watchedFileChanged(QString))); } const QString filePath = url().toLocalFile(); if (QFile::exists(filePath) && !m_fileWatcher->files().contains(filePath)) { m_fileWatcher->addPath(filePath); } } } else if (m_fileWatcher && !m_fileWatcher->files().isEmpty()) { m_fileWatcher->removePaths(m_fileWatcher->files()); } // Autofill m_passwordEntries = mApp->autoFill()->completePage(this); // AdBlock cleanBlockedObjects(); }
void PinchViewport::setLocation(const FloatPoint& newLocation) { FloatPoint clampedOffset(clampOffsetToBoundaries(newLocation)); if (clampedOffset == m_offset) return; m_offset = clampedOffset; ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator(); ASSERT(coordinator); coordinator->scrollableAreaScrollLayerDidChange(this); mainFrame()->loader().saveScrollState(); }
WebPage::WebPage(QObject *parent) : QWebPage(parent) , m_openTargetBlankLinksIn(TabWidget::NewWindow) , m_javaScriptExternalObject(0) , m_javaScriptAroraObject(0) { setPluginFactory(webPluginFactory()); setNetworkAccessManager(BrowserApplication::networkAccessManager()); connect(this, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(handleUnsupportedContent(QNetworkReply *))); connect(this, SIGNAL(frameCreated(QWebFrame *)), this, SLOT(addExternalBinding(QWebFrame *))); addExternalBinding(mainFrame()); loadSettings(); }
void Page::settingsChanged(SettingsDelegate::ChangeType changeType) { switch (changeType) { case SettingsDelegate::StyleChange: setNeedsRecalcStyleInAllFrames(); break; case SettingsDelegate::ViewportDescriptionChange: if (mainFrame()) mainFrame()->document()->updateViewportDescription(); break; case SettingsDelegate::MediaTypeChange: m_mainFrame->view()->setMediaType(AtomicString(settings().mediaTypeOverride())); setNeedsRecalcStyleInAllFrames(); break; case SettingsDelegate::DNSPrefetchingChange: for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext()) frame->document()->initDNSPrefetch(); break; case SettingsDelegate::MultisamplingChange: { HashSet<MultisamplingChangedObserver*>::iterator stop = m_multisamplingChangedObservers.end(); for (HashSet<MultisamplingChangedObserver*>::iterator it = m_multisamplingChangedObservers.begin(); it != stop; ++it) (*it)->multisamplingChanged(m_settings->openGLMultisamplingEnabled()); break; } case SettingsDelegate::ImageLoadingChange: for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext()) { frame->document()->fetcher()->setImagesEnabled(settings().imagesEnabled()); frame->document()->fetcher()->setAutoLoadImages(settings().loadsImagesAutomatically()); } break; case SettingsDelegate::TextAutosizingChange: // FTA needs both setNeedsRecalcStyle and setNeedsLayout after a setting change. if (RuntimeEnabledFeatures::fastTextAutosizingEnabled()) { setNeedsRecalcStyleInAllFrames(); } else { // FIXME: I wonder if this needs to traverse frames like in WebViewImpl::resize, or whether there is only one document per Settings instance? for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext()) { TextAutosizer* textAutosizer = frame->document()->textAutosizer(); if (textAutosizer) textAutosizer->recalculateMultipliers(); } } // TextAutosizing updates RenderStyle during layout phase (via TextAutosizer::processSubtree). // We should invoke setNeedsLayout here. setNeedsLayoutInAllFrames(); break; case SettingsDelegate::ScriptEnableChange: m_inspectorController->scriptsEnabled(settings().scriptEnabled()); break; case SettingsDelegate::FontFamilyChange: for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext()) frame->document()->styleEngine()->updateGenericFontFamilySettings(); setNeedsRecalcStyleInAllFrames(); break; } }